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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,898
Community Members
 
Community Events
184
Community Groups

Bitbucket pipeline heroku-deploy config var "Failed to replace env in config"

Edited

I recently had to change one of my app's dependencies to a private repo on AWS Codeartifact. In order to pull from this private registry, I am logging in via the AWS CLI in  the pipeline script steps, which I am able to do. This gives me an auth token which I set as an env variable (CODEARTIFACT_AUTH_TOKEN) and applies to my .npmrc file. This all works during the initial build step of my pipeline. 

@zuri-fertility:registry=https://artifacts-zuri.../
//artifacts-zuri.../:always-auth=true
//artifacts-zuri.../:_authToken=${CODEARTIFACT_AUTH_TOKEN}

The last step of my pipeline is using the atlassian/heroku-deploy:2.0.0 pipe, and I am unable to get the env variable to be referenced in this pipe. The echo directly before it correctly shows the auth token, but I can't get it to be referenced in the heroku-deploy pipe. 

- step:
name: Deploy to production
deployment: production
caches:
- pip
script:
- if [ -e set_env.sh ]; then
- cat set_env.sh
- source set_env.sh
- fi
- echo $CODEARTIFACT_AUTH_TOKEN
- echo "export CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN"
- pipe: atlassian/heroku-deploy:2.0.0
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_STAGING_NAME
ZIP_FILE: cms-service.tar.gz
CONFIG_VARS: >
{
"CODEARTIFACT_AUTH_TOKEN": $CODEARTIFACT_AUTH_TOKEN
}

Here is the error that I get:

-----> Installing dependencies
Installing node modules (yarn.lock)
yarn install v1.22.19
error An unexpected error occurred: "Failed to replace env in config: ${CODEARTIFACT_AUTH_TOKEN}".
info If you think this is a bug, please open a bug report with the information provided in "/tmp/build_78066afc/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
-----> Build failed

I have attempted many solutions but can't get this variable to be loaded at the proper time for the yarn install to work during build time. Do you have any recommendations for me? Is the syntax of the CONFIG_VARS correct? 

Thanks! 

1 answer

1 accepted

0 votes
Answer accepted

Updating: 

I realized I could run an "update" action step before trying to the deploy to production. This properly sets the config var in heroku. I am getting a different error, but this solves the initial issue so I'm closing this ticket.

Here are my bitbucket pipeline steps in case this helps anyone.  

- step: 
name: Set Codeartifact env variable
script:
- if [ -e set_env.sh ]; then
- cat set_env.sh
- source set_env.sh
- fi
- echo $CODEARTIFACT_AUTH_TOKEN
- echo "export CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN"
- pipe: atlassian/heroku-deploy:2.0.0
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_STAGING_NAME
ACTION: "update"
CONFIG_VARS: >
{
"CODEARTIFACT_AUTH_TOKEN": $CODEARTIFACT_AUTH_TOKEN
}
artifacts:
- cms-service.tar.gz

- step:
name: Deploy to production
deployment: production
script:
- pipe: atlassian/heroku-deploy:2.0.0
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_STAGING_NAME
ZIP_FILE: cms-service.tar.gz

 I am still getting this error: 

error An unexpected error occurred: "https://artifacts-zuri.../@nestjs/common/-/common-8.4.7.tgz: Request failed \"401 Unauthorized\"".

On down the rabbit hole... 

Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Oct 28, 2022

@John Kreisher  hi. 401 means you can't pull from your private AWS Registry.

You should determine in which step this error occurs. Please, provide detailed logs output, maybe I can help you.

Regards, Igor

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events