Search code examples
jenkinsjenkins-pipelinecypress

Can you update your cypress.dev.config.ts file to exclude certain tests while running a Jenkins pipeline?


I have an application that runs Cypress e2e tests. Most of the tests are pretty stable - as long as I run them locally. When I run them by deploying to a dev environment through a Jenkins pipeline they get a lot less stable and inconsistent though.

I would like to exclude some of them when running the Jenkins pipeline while still running others.

Is there a way to update my cypress.dev.config.ts file such that it excludes certain tests while running them in the Jenkins pipeline?

This is a stripped down version of my cypress.dev.config.ts file so far. Thanks.

import { defineConfig } from "cypress";

export default defineConfig({
  defaultCommandTimeout: 60000,
  execTimeout: 60000,
  pageLoadTimeout: 120000,
  taskTimeout: 60000,
  requestTimeout: 120000,
  responseTimeout: 120000,
  viewportWidth: 1600,
  viewportHeight: 1100,
  e2e: {
    env: {
      loginUrl: '',
      loginOrigin: ''
    }
  },
  reporter: 'junit',
  reporterOptions: {
    mochaFile: 'results/cypress-report-[hash].xml',
    jenkinsMode: true
  }

});


Solution

  • I'm presuming cypress.dev.config.ts is fulfilling the role of cypress.config.ts, and that it's used for both the Jenkins run and cypress open run.

    You could set a CYPRESS_jenkins env var when running under Jenkins, then use this code to change the excludeSpecPattern configuration

    A String or Array of glob patterns used to ignore test files

    import { defineConfig } from 'cypress'
    
    export default defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          if (config.env.jenkins) {
            config.excludeSpecPattern = [
              'do-not-run-me-in-jenkins.cy.ts',
            ]
          }
          return config
        },
      },
    
    })