0

I am new to use the drone secrets, need help in below. I have defined few secrets in the drone.io secrets settings. And now I want to access them in my test file.

Now in my repo there is a file called production.yml file in which I have defined the secrets values like below.

- name: build
    shm_size: 4096000000
    image: cypress/included:10.11.0
    environment:
     CYPRESS_CLIENT_KEY_PROD:
       from_secret: CYPRESS_SECRET_KEY_PROD
     CYPRESS_CLIENT_KEY_STAG:
       from_secret: CYPRESS_SECRET_KEY_STAG
    commands:
      - echo $CYPRESS_CLIENT_KEY_PROD
      - echo $CYPRESS_CLIENT_KEY_STAG

When I run the build I can see the echo prints with ****. Now I want these values to use in my test to authenticate a user. My question is what is the syntax to use these variables in my code? I tried multiple ways but nothing is working.

export function xClientKey() {
    process.env.CYPRESS_CLIENT_KEY_PROD
  };

I have created a function like above to access the secrets. But the syntax process.env.CYPRESS_CLIENT_KEY_PROD is not working here. I also tried Cypress.env.CYPRESS_CLIENT_KEY_PROD and this is also not working. It I am unable to access the secrets values. Can anyone let me know the correct syntax to access the secrets. Thanks

1 Answers1

0

In environment variables section of the docs

Any exported environment variables set on the command line or in your CI provider that start with either CYPRESS_ or cypress_ will automatically be parsed by Cypress.

So you will be able to access the variable in your test code using Cypress.env()

export function xClientKey() {
    Cypress.env('CLIENT_KEY_PROD')
  };

You can access it with config.env in node,

export function xClientKey() {
    config.env.CLIENT_KEY_PROD
  };
jjhelguero
  • 2,281
  • 5
  • 13
  • The above solution is not working. As I mentioned, these are secrets defined in the drone.io settings. And the environment setting is done in the .production.yml file. setting them in the config file would work? As these are pipeline level changes. What i mean is I am setting the env variables in yml file as under environment but in config file we store under env. So how will Cypress.env() work in this case? Please correct me here. – Tamal_bruce Mar 27 '23 at 13:58