Running Gwen on Jenkins
Jenkins job
Since v3.16.0, the
init --jenkins
command was introduced to generate a Jenkins file in your project. You will need to create the file manually if you are using an older version.
To run your Gwen project in Jenkins, get your Gwen project running in Docker first. Then create a Jenkins pipeline file in your project as shown below.
- Yarn
- npm
- pnpm
Run the following command in the root of your project to generate a Jenkins pipeline file
yarn gwen init --jenkins
Run the following command in the root of your project to generate a Jenkins pipeline file
npm run gwen init --jenkins
Run the following command in the root of your project to generate a Jenkins pipeline file
pnpm gwen init --jenkins
The following file will be created
./project # Your project root
└── /gwen
└──Jenkinsfile # Jenkins pipeline script file
With the following content
pipeline {
agent {
// replace with an agent that has docker installed
label 'docker-agent'
}
parameters {
choice(name: 'env', choices: ['dev', 'test', 'staging', 'prod'], description: 'Target environment')
choice(name: 'browser', choices: ['chrome', 'firefox', 'edge'], description: 'Target web browser')
booleanParam(name: 'dry_run', defaultValue: false, description: 'Validate without executing')
booleanParam(name: 'parallel', defaultValue: false, description: 'Enable parallel execution')
choice(name: 'threads', choices: ['auto', '2', '4', '8', '12', '16', '24', '32', '48', '64'], description: 'Number of parallel threads (auto = one thread per available core)')
booleanParam(name: 'headless', defaultValue: false, description: 'Enable headless browser')
booleanParam(name: 'video', defaultValue: true, description: 'Enable video capture (not available with parallel or headless)')
}
environment {
GWEN_ENV = "${params.env}"
GWEN_BROWSER = "${params.browser}"
GWEN_DRY_RUN = "${params.dry_run}"
GWEN_PARALLEL = "${params.parallel}"
GWEN_THREADS = "${params.threads}"
GWEN_HEADLESS = "${params.headless}"
GWEN_VIDEO = "${params.video}"
}
stages {
stage("Prepare") {
steps {
script {
// Prepare output dir
sh 'mkdir -p gwen/output'
sh 'rm -rf gwen/output/**'
}
}
}
stage("Gwen") {
steps {
try {
// Spin up environment and execute Gwen in docker
sh "docker-compose -p ${env.BUILD_TAG.toLowerCase()} -f gwen/docker-compose.yml run gwen"
if (!fileExists('gwen/output/reports/html/index.html')) {
error 'Evaluation report not generated'
}
} catch(err) {
if (fileExists('gwen/output/reports/html/index.html')) {
unstable 'Gwen completed with failure(s) reported.'
} else {
error "Gwen failed to execute or complete: ${err.getMessage()}"
}
}
}
post {
always {
sh "docker-compose -p ${env.BUILD_TAG.toLowerCase()} -f gwen/docker-compose.yml down || true"
archiveArtifacts artifacts: 'gwen/output/reports/**'
publishHTML(target: [
allowMissing : true,
alwaysLinkToLastBuild : false,
keepAll : true,
reportDir : "gwen/output/reports/html",
reportFiles : 'index.html',
reportName : "Gwen-Report"
])
}
failure {
script {
// something went wrong, raise alert here
}
}
}
}
}
}
Push or commit your project to a Git repostitory
- Checkout your Gwen project from Git
- Specify the
gwen/Jenkinsfile
above as the script - Save the job
Schedule or manually trigger your Jenkins job
- Evaluation reports will be generated and published on each run (Gwen-Report links)