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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pipelines: Error using echo to create file

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?


1 answer

0 votes


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:

- step:
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
- 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= .
- gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin
- 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.

  • break each command to their own line, getting their own error
  • download the full log, sometime snot all message show in UI
  • add debug commands like "echo $GCLOUD_PROD" without redirect (ensure variable is set to secure in repo settings to mask it.
  • add ls command after echo to make sure it was written.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

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

3,784 views 10 16
Read article

Community Events

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

Events near you