Pipelines: Incorrect environment variable's value displayed

Issue #14988 wontfix
Ronald Chia
staff created an issue


With environment variable set as below: V_NAME=my_test1 my_test1_id=135

Pipelines display "0" instead of "135" with the following command:

+ echo ${V_NAME}_id
+ echo $[${V_NAME}_id]


Tried running with docker locally and below is the output:

root@56100f3cf9dd:/opt/atlassian/bitbucketci/agent/build# echo ${V_NAME}_id
root@56100f3cf9dd:/opt/atlassian/bitbucketci/agent/build# echo $[${V_NAME}_id]

Comments (26)

  1. Kamlesh

    This issue has blocked our entire pipeline workflow. As this is the usual/normal use case, please suggest me an alternative work around so our CI/CD flows are not blocked

  2. Luke Batchelor

    For what it's worth, I was curious and tried to reproduce and it seems to work fine for me locally and in Pipelines


    Is it possible you are setting those variables in a script and not sourcing the files, hence not getting the exported variables?

    i.e, in our build we have

    - source ./build-setup.sh
    - echo "$PATH"
  3. Kamlesh

    I am setting these via environment variables. Hence I get 0. But when I directly write echo my_test1_id I get output as expected. Which means I am not able to evaluate the value dynamically in the way echo $[${V_NAME}_id]

  4. Jeroen De Raedt staff

    Hi Kamlesh, do you mind sharing which Docker image you are using? Given for some this is working, I suspect the Docker image somehow impacts the results that you are seeing.

  5. Kamlesh

    It's been a long time since this is opened. Can we please address it or you guys can look into it as I have mentioned all the details and still I am unable to achieve this

  6. Sebastian Cole staff

    Hey @Kamlesh,

    I've just tried to recreate using debian:jessie, and node:8.5, using a combination of exported variables (from within the script), and variables defined in the UI. Everything works as expected.

    Screen Shot 2017-11-09 at 2.15.11 pm.png

    Could you please reach out via https://getsupport.atlassian.com so we can look into the specifics of your pipeline to figure out what's happening. (or link me to an existing support case if you've got it handy)

    thanks, Seb

  7. Sebastian Cole staff

    Ok, I've been able to understand this a bit more;

    The issue appears to be where the inner variable NAME or V_NAME in the above example, contain an alpha-numeric value, instead of a numeric value.

    I believe there's some behaviour in the bash operation $[ ] that is not compatible with what you're trying to do. I'm looking into this more, but I believe the core requirement is that you can run the equivalent of

    echo ${${VAR}_postfix} => value

    where name_postfix can contain alpha-numeric values

  8. Log in to comment