Cypress tests failing in GitLab CICD Pipeline due to Environment variables. #14203
-
cc : @jennifer-shehane @brian-mann On local everything runs fine, as I provide --env env=qa in command CLI. So, I tried changing my code and in test files I wrote : const env = Cypress.env('qa'); This works perfectly. Thanks and regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you want to load and set different environment variables based on We have a recipe that shows several ways of setting and passing environment variables here https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/server-communication__env-variables And I have a section in my "Cypress tips and tricks" blog post specifically describing an example https://glebbahmutov.com/blog/cypress-tips-and-tricks/#pass-the-environment-variables-correctly In your case the module.exports = (on, config) => {
const envName = process.env.ENV || process.env.NODE_ENV || 'qa'
console.log('using env %s', envName)
// we want to use baseUrl depending on the env name
const baseUrl = config.env[envName].baseURL
if (baseUrl) {
console.log('setting base URL to %s', baseUrl)
config.baseUrl = baseUrl
}
// return config with changed variables
return config
} |
Beta Was this translation helpful? Give feedback.
If you want to load and set different environment variables based on
process.env
values, you need to use the plugins file https://on.cypress.io/environment-variables#Option-5-PluginsWe have a recipe that shows several ways of setting and passing environment variables here https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/server-communication__env-variables
And I have a section in my "Cypress tips and tricks" blog post specifically describing an example https://glebbahmutov.com/blog/cypress-tips-and-tricks/#pass-the-environment-variables-correctly
In your case the
cypress/plugins/index.js
file would have something like