Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 367
Hesham Abboud Avatar asked Sep 19 '25 16:09

Hesham Abboud


1 Answers

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

like image 116
N1ngu Avatar answered Sep 23 '25 10:09

N1ngu