Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Environment variables from my project settings not properly working in my pipelines

kalib April 19, 2022

I am trying to use some environment variables in my bitbucket pipeline scripts and it looks like the variables are not being passed, for example:

- VERSION=${BITBUCKET_TAG:-${BITBUCKET_BRANCH//\//_}-latest}
- IMAGE_NAME="${NEXUS_DOCKER_PRIVATE_REGISTRY_URL}/baseline-service:${VERSION}"
- docker build . -t $IMAGE_NAME --pull --no-cache --label 'GIT_COMMIT_HASH=$BITBUCKET_COMMIT'

In that case, NEXUS_DOCKER_PRIVATE_REGISTRY_URL is my environment variable, but it's not being translated properly:

+ docker build . -t $IMAGE_NAME --pull --no-cache --label 'GIT_COMMIT_HASH=$BITBUCKET_COMMIT'
invalid argument "$NEXUS_DOCKER_PRIVATE_REGISTRY_URL/my-service:feature_pipeline-latest" for "-t, --tag" flag: invalid reference format

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 20, 2022 edited

Hello @kalib ,

From the error message seems like the IMAGE_NAME variable was not populated correctly. Checking the syntax you have used in IMAGE_NAME, it seems to be correct, and testing on my repository it was correctly presenting the value.

 

Could you please confirm if the NEXUS_DOCKER_PRIVATE_REGISTRY_URL has not any typo when you created it in your repository settings/workspace settings ?

One thing you can also do for troubleshooting is to print the variables using echo after you have created them and see if the value is correct, like below :

 

- VERSION=${BITBUCKET_TAG:-${BITBUCKET_BRANCH//\//_}-latest}
- echo $VERSION - IMAGE_NAME="${NEXUS_DOCKER_PRIVATE_REGISTRY_URL}/baseline-service:${VERSION}"
- echo $IMAGE_NAME
- echo $NEXUS_DOCKER_PRIVATE_REGISTRY_URL

Would you please try the above and let us know the output ?

Thank you, @kalib .

Kind regards,

Patrik S

kalib April 20, 2022 edited

Thanks, this method for validation worked for me as well. Thanks, it will make it way easier for troubleshooting.

Like • Patrik S likes this
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 20, 2022

Hey @kalib ,

Awesome! It's indeed way easier to investigate when printing the variable value with echo. Do let us know in case you have any other questions.

Kind regards,

Patrik S

Like • kalib likes this

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, out of office, loom, confluence, async collaboration, meeting recaps, remote teamwork, team alignment, knowledge sharing, AI-powered notes, productivity tools, workforce continuity, teamwork collection

Put your meeting notes on autopilot with Loom + Confluence

AI-powered meeting notes keep work moving even if you’re out of the office. Enjoy your well-deserved time off and return refreshed, confident you’ll catch up in no time.

Learn more
AUG Leaders

Atlassian Community Events