Cannot skip cypress test based on environment variable

Viewed 444

I am trying to skip a few cypress tests within a certain jenkins environment. My cypress tests look like this:

if (!Cypress.env.DEV_JENKINS) {
    it.only("should run if not on a the DEV_JENKINS environment", () => {
       // ...
    });
    
    // more tests
  }

I know that this code works to skip tests, because if I change it to if (Cypress.env.DEV_JENKINS), the tests are skipped, because there is no environment variable set.

I am trying every possible way described in the cypress docs to set this environment variable from the cli. Here are a few things I've tried:

npx cypress run --env DEV_JENKINS=true

CYPRESS_DEV_JENKINS=true npx cypress run

export CYPRESS_DEV_JENKINS=true && npx cypress run

It seems like no matter what I do, the tests are not being skipped. I have a feeling I'm not setting the env variable correctly, but I don't see whats wrong. How can I successfully set the environment variable from my jenkins pipeline so that cypress will register it and skip certain tests based on the above code?

1 Answers

Env variables are strings, so

if (Cypress.env.DEV_JENKINS !== 'true') {   

is a bit more explicit.


Are you trying to skip by not setting DEV_JENKINS?

if (!Cypress.env.DEV_JENKINS) {

should skip if you don't have the env.

If you ran it first with DEV_JENKINS and then without, is the env variable persisting for the 2nd run?

Related