Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash's declare in .travis.yml #3149

Closed
wsfulton opened this issue Jan 29, 2015 · 1 comment
Closed

Bash's declare in .travis.yml #3149

wsfulton opened this issue Jan 29, 2015 · 1 comment

Comments

@wsfulton
Copy link

In the .travis.yml file export works as it normally would in bash. declare does not seem to do the same. I've tried using 'declare -x' to export the variable and declare followed by export, but this does not work. What is happening to stop this working properly? It's as if each line in the .travis.yml is run in a new shell, except this can't be the case as more usual setting of variables with export do work.

Here are some experiments I did using this .travis.yml:

  - export TESTER1="tester1"
  - echo $TESTER1
  - declare -x TESTER2="tester2" && declare -p TESTER2
  - declare -p TESTER2 || true
  - echo $TESTER2 || true
  - declare -x TESTER3="tester3" && declare -p TESTER3 && export TESTER3 && declare -p TESTER3
  - declare -p TESTER3 || true
  - echo $TESTER3 || true

and output on Travis:

$ export TESTER1="tester1"
$ echo $TESTER1
tester1
$ declare -x TESTER2="tester2" && declare -p TESTER2
declare -x TESTER2="tester2"
$ declare -p TESTER2 || true
/home/travis/build.sh: line 41: declare: TESTER2: not found
$ echo $TESTER2 || true

$ declare -x TESTER3="tester3" && declare -p TESTER3 && export TESTER3 && declare -p TESTER3
declare -x TESTER3="tester3"
declare -x TESTER3="tester3"
$ declare -p TESTER3 || true
/home/travis/build.sh: line 41: declare: TESTER3: not found
$ echo $TESTER3 || true

So export TESTER1 works and the rest only work on the one line and not on the next line of the .travis.yml file. I can move this logic into a script to workaround it, but I'm intrigued as to why it does not work.

Why do I want to use declare instead of simple variables? Well, I would really like to use 'declare -A' for associative arrays.

@BanzaiMan
Copy link
Contributor

Under the hood, each item in the script sequence is passed a Bash function so that we can write logs in an informative way. This is bad news for declare, since the scope of the variables defined therein is restricted to the Bash function.

I see what you want to accomplish, but this is not simply possible with the current implementation.

It is best to write a script instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants