I'm having a problem when executing automatic pipelines (from a commit in a branch) with this code block below.
echo $GCLOUD_PROD > auth_base.json | base64 -d auth_base.json > auth.json | gcloud auth activate-service-account --key-file auth.json
It always fails. When a manually start it from GUI it works.
Can anyone help me?
echo $GCLOUD_PROD > auth_base.json | base64 .....
I'm not understanding how this works anywhere...
The first io redirect `>` would redirect all stdout to that file, so only stderr would be passed through the pipe to base64 and subsequent commands.
Also, to get more accurate help, what is the purpose of the 2 auth files?
Typically I see base64 decoding of environment variables handled like this, with any subsequent commands broken to their own line to use the decoded file.
- echo $GCLOUD_PROD | base64 -d > auth.json
- gcloud auth activate-service-account --key-file auth.json
It´s working (when started manually) in a bunch of projects. See the attached image.
That's because de subsequent commands do not need the stdout and/or stderr.
They are working with the file created.
I divided it into two files only to make more clear the process.
First, get the base64 env and create a file, after convert that base64 file to a plain text file.
And, so then, log into gcp.
OK, I see, so you're just using pipes to chain the commands? I've not seen that pattern.
Anyway, can you send a failure example? I see your working example is a deployment, is it possible the Variable is not available to your automatic runs? (which may not be specifying an environment to access environment specific variables?)
I did not specify env for a specific environment. That is useful, can you point me a doc to do that?
Below is my script:
name: Build image
script: # compila a imagem e sobe ela para o repositório de imagens
- echo $GCLOUD_PROD > auth_base.json | base64 -d auth_base.json > auth.json | gcloud auth activate-service-account --key-file auth.json
- export IMAGE_NAME=gcr.io/hcms-prod/hcms-salessurvey-frontend:$BITBUCKET_COMMIT
- docker build -t $IMAGE_NAME --build-arg REACT_APP_BASE_URL='' --build-arg REACT_APP_TOKEN_SECRET=hcmsjsonwebtokensecretapiPPRDO --build-arg REACT_APP_BASE_URL_SURVEY=/survey --build-arg REACT_APP_KIBANA_URL=https://1a97ebd98d4047208c895b2c2b2f3828.southamerica-east1.gcp.elastic-cloud.com:9243 .
- gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
- docker push $IMAGE_NAME
For the environment variables:
Deployment variables override both team and repository variables. Also variables with the same name can have different values for each deployment environment. For example, you could set a different $DEPLOYMENT_SECRET_KEY for each environment
For the error... I'm stumped!
base64 is throwing the error, not finding file. So my mind goes to the previous command, echo. Echo's simplicity has me wondering about the variable.
I personally would either debug locally or try to isolate cause with lots of debug statements to isolate cause.
Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events