All Downloads are FREE. Search and download functionalities are using the official Maven repository.

init.Jenkinsfile Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
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.initDir}${slash}output'
          sh 'rm -rf ${gwen.initDir}${slash}output/**'
        }
      }
    }
    stage("Gwen") {
      steps {
        script {
          try {
            // Spin up environment and execute Gwen in docker
            sh "docker-compose -p ${env.BUILD_TAG.toLowerCase()}${docker.compose.options} run gwen"
            if (!fileExists('${gwen.initDir}${slash}output/reports/html/index.html')) {
              error 'Evaluation report not generated'
            }
          } catch(err) {
            if (fileExists('${gwen.initDir}${slash}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()}${docker.compose.options} down || true"
          archiveArtifacts artifacts: '${gwen.initDir}${slash}output/reports/**'
          publishHTML(target: [
                        allowMissing          : true,
                        alwaysLinkToLastBuild : false,
                        keepAll               : true,
                        reportDir             : '${gwen.initDir}${slash}output/reports/html',
                        reportFiles           : 'index.html',
                        reportName            : "Gwen-Report"
          ])
        }
        failure {
          script {
            // something went wrong, raise alert here
          }
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy