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

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

John Kreisher October 22, 2022

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
John Kreisher October 24, 2022

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.
October 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