Nael Marwan
Nael Marwan

Reputation: 1038

Jenkins Pipeline 'Wrap' Stages for Xvfb start

I'm trying to wrap stages by using:

      wrap([$class: 'Xvfb', additionalOptions: '', assignedLabels: '', autoDisplayName: true, debug: true, displayNameOffset: 100, installationName: 'XVFB', parallelBuild: true]) {

If I have Jenkins file with below lines, how can I start the Xvfb first then start running the tests suite? In other words how to wrap the stages?

pipeline {

agent any 
             parameters{
             choice(choices: 'chrome\nfirefox\nie' , description: 'choose browser name' , name: 'browser')
             choice(choices: 'false\ntrue'  , description: 'Not running on Selenium Grid?' , name: 'localRun')
        }

stages {
      stage('Install Parent Project') {
        steps {
        sh 'mvn -f /var/lib/jenkins/workspace/ clean install -DskipTests=true'
        }
    }
}

Thanks.

Upvotes: 6

Views: 5698

Answers (2)

Nael Marwan
Nael Marwan

Reputation: 1038

Here is how to add the wrap block with timeout:

    stage('Run Tests Suite') {
        steps {
         timeout(45) {
         wrap([$class: 'Xvfb', additionalOptions: '', assignedLabels: '', autoDisplayName: true, debug: true, displayNameOffset: 0, installationName: 'XVFB', parallelBuild: true, screen: '1024x758x24', timeout: 25]) {
        sh 'mvn  -f /var/lib/jenkins/workspace/... test -DlocalRun=${localRun} -Dbrowser=${browser} -DxmlPath='''
        }
        }
    }      
    }

Upvotes: 6

yong
yong

Reputation: 13722

You can put the first stage inside the wrap

stages {
    wrap([$class: 'Xvfb', ....) {
        stage('Install Parent Project') {
            steps {
            sh 'mvn -f /var/lib/jenkins/workspace/ clean install -DskipTests=true'
            }
        }
    }
}

Upvotes: 0

Related Questions