Reputation: 33
I'm trying to port an existing Jenkins job to a Jenkinsfile. For the most part this works well but I have been unable to figure out how to make use of the Xvnc plugin. In the old Jenkins job the plugin is configured as
Which is required to set the DISPLAY environment variable so that Chrome can run. The error I see in the Jenkins build output is
[32m27 07 2018 09:21:30.798:INFO [karma]: [39mKarma v2.0.3 server started at http://0.0.0.0:9876/
[32m27 07 2018 09:21:30.800:INFO [launcher]: [39mLaunching browser Chrome with unlimited concurrency
[32m27 07 2018 09:21:30.819:INFO [launcher]: [39mStarting browser Chrome
[31m27 07 2018 09:21:31.277:ERROR [launcher]: [39mCannot start Chrome
My (truncated) Jenkinsfile looks like this
pipeline {
agent {
label 'java8&&chrome'
}
stages {
stage ("Build") {
tools {
jdk 'jdk 1.8'
}
steps {
step ([$class: 'Xvnc', useXauthority: 'true'])
//wrap ([$class: 'Xvnc', useXauthority: 'true'])
//xvnc { useXauthority(true) }
sh './gradlew clean build -PsnapshotDeps'
}
}
}
}
I suspect that I need to enclose the gradle step with the Xvnc wrapper in some way, but none of the options have tried have been any more successful than the options that I have tried here.
Upvotes: 3
Views: 3706
Reputation: 11470
The wrap command is followed by a block. Everything inside the block is under the effect of the wrapper (https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#wrap-general-build-wrapper).
stages {
stage('Build') {
steps {
wrap([$class: 'Xvnc', takeScreenshot: false, useXauthority: true]) {
sh './gradlew clean build -PsnapshotDeps'
}
}
}
}
The output should contain something like this:
[Pipeline] wrap
Starting xvnc
[jobname] $ vncserver :96 -localhost -nolisten tcp
addition: As stated in the comments Xvnc plugin has pipeline support added since 1.22.
For karma there is also the possibility to use ChromeHeadless which would not requiere any vnc server at all. But I am not sure if this also works for gradle karma.
Upvotes: 4