Skip to content

Commit 8d88f75

Browse files
author
Patrick Cadelina
committed
Add support for Xvfb Plugin
1 parent f88f644 commit 8d88f75

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

docs/Job-reference.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ freeStyleJob(String name) { // since 1.30
117117
timeout(Closure timeoutClosure = null)
118118
timestamps()
119119
toolenv(String... tools)
120+
xvfb(String installation)
120121
xvnc(boolean takeScreenshot) // deprecated
121122
xvnc(Closure xvncClosure = null) // since 1.26
122123
}
@@ -1667,6 +1668,29 @@ job('example') {
16671668

16681669
(Since 1.19)
16691670

1671+
### Xvfb
1672+
1673+
```groovy
1674+
job {
1675+
wrappers {
1676+
xvfb('xvfb') {
1677+
screen '1024x768x24' // defaults to 1024x768x24
1678+
debug(boolean debug = true) // defaults to false
1679+
timeout(int timeout) // defaults to 0
1680+
displayNameOffset(int displayNameOffset) // defaults to 1
1681+
shutdownWithBuild(boolean shutdownWithBuild = true) // defaults to false
1682+
autoDisplayName(boolean autoDisplayName = true) // defaults to false
1683+
assignedLabels 'xvfb'
1684+
parallelBuild(boolean parallelBuild = true) // defaults to false
1685+
}
1686+
}
1687+
}
1688+
```
1689+
1690+
Lets you control Xvfb virtual frame buffer X11 server with each build. It starts Xvfb before the build starts, and stops
1691+
it with the build. This is very useful if your build requires X11 access, for instance runs tests that require GUI.
1692+
Requires the [Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin).
1693+
16701694
### Xvnc
16711695

16721696
```groovy

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContext.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package javaposse.jobdsl.dsl.helpers.wrapper
22

33
import com.google.common.base.Preconditions
4+
45
import hudson.util.VersionNumber
56
import javaposse.jobdsl.dsl.Context
67
import javaposse.jobdsl.dsl.ContextHelper
@@ -308,6 +309,46 @@ class WrapperContext implements Context {
308309
}
309310
}
310311

312+
/**
313+
* <pre>
314+
* {@code
315+
* <project>
316+
* <buildWrappers>
317+
* <org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
318+
* <installationName>xvfb</installationName>
319+
* <screen>1024x768x24</screen>
320+
* <debug>false</debug>
321+
* <timeout>0</timeout>
322+
* <displayNameOffset>1</displayNameOffset>
323+
* <shutdownWithBuild>false</shutdownWithBuild>
324+
* <autoDisplayName>false</autoDisplayName>
325+
* <assignedLabels>xvfb</assignedLabels>
326+
* <parallelBuild>false</parallelBuild>
327+
* </org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
328+
* </buildWrappers>
329+
* </project>
330+
* }
331+
*
332+
* Runs build under XVFB.
333+
* @param name of the Xvfb tool installation that Jenkins administrator set up
334+
*/
335+
void xvfb(String installation, @DslContext(XvfbContext) Closure closure = null) {
336+
XvfbContext context = new XvfbContext(installation)
337+
ContextHelper.executeInContext(closure, context)
338+
339+
wrapperNodes << new NodeBuilder().'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper' {
340+
installationName(context.installationName)
341+
screen(context.screen)
342+
debug(context.debug)
343+
timeout(context.timeout)
344+
displayNameOffset(context.displayNameOffset)
345+
shutdownWithBuild(context.shutdownWithBuild)
346+
autoDisplayName(context.autoDisplayName)
347+
assignedLabels(context.assignedLabels)
348+
parallelBuild(context.parallelBuild)
349+
}
350+
}
351+
311352
/**
312353
* <pre>
313354
* {@code
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package javaposse.jobdsl.dsl.helpers.wrapper
2+
3+
import javaposse.jobdsl.dsl.Context
4+
5+
class XvfbContext implements Context {
6+
String installationName
7+
String screen = '1024x768x24'
8+
boolean debug = false
9+
int timeout = 0
10+
int displayNameOffset = 1
11+
boolean shutdownWithBuild = false
12+
boolean autoDisplayName = false
13+
String assignedLabels
14+
boolean parallelBuild = false
15+
16+
XvfbContext(String installationName) {
17+
this.installationName = installationName
18+
}
19+
20+
void installationName(String installationName) {
21+
this.installationName = installationName
22+
}
23+
24+
void screen(String screen) {
25+
this.screen = screen
26+
}
27+
28+
void debug(boolean debug = true) {
29+
this.debug = debug
30+
}
31+
32+
void timeout(int timeout) {
33+
this.timeout = timeout
34+
}
35+
36+
void displayNameOffset(int displayNameOffset) {
37+
this.displayNameOffset = displayNameOffset
38+
}
39+
40+
void shutdownWithBuild(boolean shutdownWithBuild = true) {
41+
this.shutdownWithBuild = shutdownWithBuild
42+
}
43+
44+
void autoDisplayName(boolean autoDisplayName = false) {
45+
this.autoDisplayName = autoDisplayName
46+
}
47+
48+
void assignedLabels(String assignedLabels) {
49+
this.assignedLabels = assignedLabels
50+
}
51+
52+
void parallelBuild(boolean parallelBuild = true) {
53+
this.parallelBuild = parallelBuild
54+
}
55+
}

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContextSpec.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,27 @@ class WrapperContextSpec extends Specification {
413413
wrapper.takeScreenshot[0].value() == false
414414
}
415415

416+
def 'xvfb' () {
417+
when:
418+
context.xvfb('default') {
419+
assignedLabels 'xvfb'
420+
}
421+
422+
then:
423+
context.wrapperNodes[0].name() == 'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper'
424+
def wrapper = context.wrapperNodes[0]
425+
wrapper.children().size() == 9
426+
wrapper.installationName[0].value() == 'default'
427+
wrapper.screen[0].value() == '1024x768x24'
428+
wrapper.debug[0].value() == false
429+
wrapper.timeout[0].value() == 0
430+
wrapper.displayNameOffset[0].value() == 1
431+
wrapper.shutdownWithBuild[0].value() == false
432+
wrapper.autoDisplayName[0].value() == false
433+
wrapper.assignedLabels[0].value() == 'xvfb'
434+
wrapper.parallelBuild[0].value() == false
435+
}
436+
416437
def 'toolenv' () {
417438
when:
418439
context.toolenv('Ant 1.8.2', 'Maven 3')

0 commit comments

Comments
 (0)