user2707671
user2707671

Reputation: 1739

How to put the content of a file in an environment variable in circleci?

I would like to use the content of a file in an environment variable in CircleCI. Is this possible? So far, I tried this in my circle.yml

machine:
  environment:
    AMI_DESCRIPTION: "$(cat DESCRIPTION.TXT)"

dependencies:
  override:
    - echo "DESC $AMI_DESCRIPTION"

But when running, it just outputs:

echo "DESC $AMI_DESCRIPTION"
DESC

I also tried to add

deployment:
  production:
    branch: master
    commands:
      - ./packer/packer build -var 'ami_desc="$(cat DESCRIPTION.TXT)"' template.json

but 'ami_desc' is still empty.

Upvotes: 6

Views: 2661

Answers (1)

Islam Salah
Islam Salah

Reputation: 983

1) Run this command on your machine.

ENV_VAR="$(cat filePath | base64)"

2) Copy the output of echo $ENV_VAR and set it manually on CircleCi

3) While CircleCi running, the file can be retrieve using :

echo $ENV_VAR | base64 --decode > filePath

Upvotes: 4

Related Questions