Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can't access environment variable

jonyt March 18, 2018

I'm trying to set up CI with Bitbucket pipelines, using a custom Docker image. I need maven to run with an environment variable but I can't get the build script to read the value of this variable. The script is:

echo "'$USERNAME'" && mvn -Dusername="'$USERNAME'" -Dpassword=. package

But then instead of getting the value of the USERNAME variable echoed I get "'$USERNAME'". Same if I echo only $USERNAME or "$USERNAME". How can I fix this?

2 answers

0 votes
mmenezes April 14, 2022

Same issue, unfortunately for this situation we need disable the secured flag. For password and username it works if pass directly without '' or "" but for url that bitbucket needs to pass using " " it doest work as expected. 

0 votes
Linette
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2018

Hi there,

Looks like you have a few too many " & "'s in there.

I set my USERNAME environment variable to Atlassian.

Screenshot 2018-03-19 13.31.19.png 

With this pipeline

pipelines: 
default:
-
step:
script:
- echo $USERNAME
-
echo '$USERNAME'

Note: when you type this in, it may try and suggest other environment variables. Don't worry and just keep typing the one you want. :)

I get the return

Screenshot 2018-03-19 12.45.23.png

I hope that helps!

jonyt March 20, 2018

I finally understood my mistake. The variable I wanted was secured and I didn't realize that Bitbucket will print VARIABLE_NAME instead of its value in that case. Another look at the manual made that clear. Thanks for helping out!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events