Hesham Abboud
Hesham Abboud

Reputation: 55

How to store a file as bitbucket pipeline variable?

I'm using bitbucket pipelines and I need to store the .env file (for example) as a variable so that I can use it in my deployment. When I stored it as a plain text variable it echoed as a single line text and the app couldn't use it.

Upvotes: 4

Views: 2549

Answers (1)

N1ngu
N1ngu

Reputation: 3805

If your file contains linebreaks, they will be mangled by the input field in the pipeline variables page.

A solution is to encode the file content with base64 and decode the variable when writing it back to a file.

base64 < .env
pipelines:
  default:
    - step:
        script: 
          - echo $MYVAR | base64 --decode > .env

Beware that if your file contains secrets and mark the base64-encoded variable as secret, you will loose a security feature that prevents accidental prints of its value in the pipeline logs. See Bitbucket: Show value of variables marked as secret

Upvotes: 4

Related Questions