Could you tell me how to set Environment Variables?

Hi there,

Can you tell me how to set Environment Variables?

Now I’ using CircleCI for my Ruby on Rails project.
I need to input several api key information. I don’t want to push these info to GitHub. So I’m trying to set them into Environment Variables.

such as like this

Environment Variables

Name
aws_access_key_id

Value
AKEIAUGA888999999FAE

secrets.ci.yml

test:
aws:
access_key_id: $aws_access_key_id

But it doesn’t work.

If I input the key into secrets.ci.yml directly, it works.

Can anyone tell me which part am I missing?

Thank you.

You can add them to your circle.yml file. If they are private you would want to add them in the settings in the CircleCi gui though.

Ref: https://circleci.com/docs/configuration/#environment

1 Like

Hi drazisil,

Thank you for your reply.
But I still not get it.

I changed my circle.yml file like this. It doesn’t work.

machine:
  ruby:
    version:
      2.1.9
  environment:
    aws_access_key_id: $aws_access_key_id
    aws_secret_access_key: $aws_secret_access_key

Can you give me an example for correct setting?

machine:
  ruby:
    version:
      2.1.9
  environment:
    aws_access_key_id: "123"
    aws_secret_access_key: "key"

You would put the values like so.

You then access them as $aws_access_key_id and $aws_secret_access_key

Hi drazisil,

I don’t want to set the value into yml file and push it to GitHub.
That’s why I set the value into Environment Variables (Project Setting > Environment Variables )

My question is how to pick up the values from Environment Variables to secrets.yml files.

Ah, my apologies. It should just work without the need for the secrets.ci.yml file

ref: How can I set secrets.yml for test environment for CircleCI?

Hi drazisil,

Can you give me an example?
I’ve already read the link document and set like below. But it doesn’t work.
It looks secrets.ci.yml file is not picking up the values from Environment Variables setting.
Do you know which part I’m missing?
Can you show us the example of yml files?

# Environment Variables
Name
  aws_access_key_id
Value
  AKEIAUGA888999999FAE
# secrets.ci.yml
test:
  aws:
    access_key_id: $aws_access_key_id

I don’t believe you need the secrets.ci file at all. Have you tried just using the variable in your code?

CircleCi doesn’t use a secrets file, any variables you set in the gui just exist and don’t need to be redefined elsewhere. If you need it to be called access_key_id for your program, call it that in the gui.

Hi drazisil,

I solved by this.
Is there an instruction that we need to add ENV[’***’]?

# secrets.ci.yml
    aws:
      access_key_id: <%= ENV['aws_access_key_id'] %>
      secret_access_key: <%= ENV['aws_secret_access_key'] %>
2 Likes