3

I can't figure out how to pass in to Gitlab CI some env variables in a json file, specifically the one I use with cypress.io.

Gitlab CI certainly has a section where you can specify env vars in the form of a variable or a file.

enter image description here

However, Gitlab CI complains with "Variables key can contain only letters, digits and '_'".

So, things I have thought about:

  1. Overriding the env file that cypress uses by using the --env and then specifying a file like
# cypress-env
{
  "username": "xxxx",
  "password": "xxxx"
}
  1. creating the file as specified in this answer https://stackoverflow.com/a/55581164/5597960

  2. Asking Cypress.io team to include an example on how to do this (their excellent documentation does not have a similar example).

  3. Researching more about specifying file variables in Gitlab CI. There is something strange about the error Gitlab produces. Why would they not allow dots in the file variable? I must be doing something wrong.

Miguel Trejo
  • 5,913
  • 5
  • 24
  • 49
fingia
  • 504
  • 7
  • 20

1 Answers1

7

Follow the next steps:

  1. Create the environment variable with a key name following the syntax required by gitlab-ci. As example, naming it json_variables

Key: Must be one line, with no spaces, using only letters, numbers, or _.

enter image description here

  1. On the Gitlab-ci job copy the contents of json_variables to a file named cypress.env.json
stages: 
  - build

development: 
  stage: build
  when: manual 
  script:
    - cp $json_variables ~/cypress.env.json
    - cat ~/cypress.env.json
  environment: development
  only:
    - dev

To verify, the output of cat is

enter image description here

Miguel Trejo
  • 5,913
  • 5
  • 24
  • 49