Skip to content

Commit 85f3031

Browse files
Rob Langleydaspilker
authored andcommitted
Most basic plot plugin usage
1 parent f88f644 commit 85f3031

File tree

7 files changed

+252
-0
lines changed

7 files changed

+252
-0
lines changed

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
1919
* 1.31 (unreleased)
2020
* Added support for [Pre-SCM Build Step Plugin](https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep)
2121
* The enum argument of `localRepository` for the Maven job and context has changed, see [[Migration]]
22+
* Added partial support for [Plot Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin)
2223
* 1.30 (March 08 2015)
2324
* Added support for [Custom Tools Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin)
2425
* Added support for [Flaky Test Handler Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Flaky+Test+Handler+Plugin)

docs/Job-reference.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ freeStyleJob(String name) { // since 1.30
226226
mailer(String recipients, Boolean dontNotifyEveryUnstableBuild = false,
227227
Boolean sendToIndividuals = false)
228228
mavenDeploymentLinker(String regex) // since 1.23
229+
plotBuildData(Closure closure) // since 1.31
229230
pmd(String pattern, Closure staticAnalysisClosure = null)
230231
postBuildTask(Closure closure) // since 1.19
231232
publishCloneWorkspace(String workspaceGlob, Closure cloneWorkspaceClosure)
@@ -3800,6 +3801,58 @@ The arguments here are in order:
38003801
* (String) the findbugs-files to parse
38013802
* (boolean) use the findbugs rank for the priority, default to false
38023803
3804+
#### [Plot Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin)
3805+
```groovy
3806+
publishers {
3807+
plotBuildData {
3808+
plot(String dataStore, String group) {
3809+
style(String style = 'line')
3810+
propertiesFile(String fileName) {
3811+
label(String label)
3812+
}
3813+
}
3814+
}
3815+
}
3816+
```
3817+
3818+
Plot plugin is able to show a number of plots, each containing a single data series.
3819+
3820+
`plot` arguments:
3821+
* `dataStore` Plot plugin relies on a data store to hold the plot data, this is normally stored in a randomly named CSV file within the workspace root. To avoid conflicts this location needs to be set manually and is within the workspace root.
3822+
* `group` Specifies to which group the plot belongs.
3823+
* `style` Optional, Specifies which chart style to display the plot data as, one of: 'area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', 'stackedbar', 'stackedbar3d', 'waterfall'.
3824+
3825+
`propertiesFile` arguments:
3826+
* `fileName` Specifies the filename that contains this data series, relative to the workspace root.
3827+
* `label` Optional, specifies the legend label for this data series.
3828+
3829+
Examples:
3830+
3831+
```groovy
3832+
publishers {
3833+
plotBuildData {
3834+
plot('my_data_store.csv', 'Important plot') {
3835+
propertiesFile('my_data.prop')
3836+
}
3837+
}
3838+
}
3839+
```
3840+
3841+
```groovy
3842+
publishers {
3843+
plotBuildData {
3844+
style('bar')
3845+
plot('bar_chart_data_store.csv', 'Bar charts') {
3846+
propertiesFile('my_data.prop') {
3847+
label('My label')
3848+
}
3849+
}
3850+
}
3851+
}
3852+
```
3853+
3854+
// since 1.31
3855+
38033856
#### [Pmd](https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin)
38043857
```groovy
38053858
publishers {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package javaposse.jobdsl.dsl.helpers.publisher
2+
3+
import javaposse.jobdsl.dsl.ContextHelper
4+
import javaposse.jobdsl.dsl.Context
5+
6+
import static com.google.common.base.Preconditions.checkArgument
7+
8+
class PlotContext implements Context {
9+
private static final List<String> STYLE = [
10+
'area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', 'stackedbar', 'stackedbar3d', 'waterfall'
11+
]
12+
13+
String style = 'line'
14+
String dataStore
15+
String group
16+
List<PlotSeriesContext> dataSeriesList = []
17+
18+
PlotContext(String dataStore, String group) {
19+
this.dataStore = dataStore
20+
this.group = group
21+
}
22+
23+
void style(String style) {
24+
checkArgument(STYLE.contains(style), "style must be one of ${STYLE.join(', ')}")
25+
this.style = style
26+
}
27+
28+
void propertiesFile(String fileName, Closure plotSeriesClosure = null) {
29+
PlotSeriesContext plotSeriesContext = new PlotSeriesContext(fileName, 'PropertiesSeries', 'properties')
30+
ContextHelper.executeInContext(plotSeriesClosure, plotSeriesContext)
31+
32+
dataSeriesList << plotSeriesContext
33+
}
34+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package javaposse.jobdsl.dsl.helpers.publisher
2+
3+
import javaposse.jobdsl.dsl.Context
4+
5+
class PlotSeriesContext implements Context {
6+
final String type
7+
final String fileType
8+
String file = ''
9+
String label = ''
10+
11+
PlotSeriesContext(String fileName, String type, String fileType) {
12+
this.file = fileName
13+
this.type = type
14+
this.fileType = fileType
15+
}
16+
17+
void label(String label) {
18+
this.label = label
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package javaposse.jobdsl.dsl.helpers.publisher
2+
3+
import javaposse.jobdsl.dsl.ContextHelper
4+
import javaposse.jobdsl.dsl.Context
5+
6+
class PlotsContext implements Context {
7+
List<PlotContext> plots = []
8+
9+
void plot(String dataStore, String group, Closure plotClosure) {
10+
PlotContext plotContext = new PlotContext(dataStore, group)
11+
ContextHelper.executeInContext(plotClosure, plotContext)
12+
13+
plots << plotContext
14+
}
15+
}

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/publisher/PublisherContext.groovy

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,77 @@ class PublisherContext implements Context {
336336
publisherNodes << jacocoNode
337337
}
338338

339+
/**
340+
* <hudson.plugins.plot.PlotPublisher>
341+
* <plots>
342+
* <hudson.plugins.plot.Plot>
343+
* <title></title>
344+
* <yaxis></yaxis>
345+
* <series>
346+
* <hudson.plugins.plot.PropertiesSeries>
347+
* <file>Properties</file>
348+
* <label></label>
349+
* <fileType>properties</fileType>
350+
* </hudson.plugins.plot.PropertiesSeries>
351+
* <hudson.plugins.plot.CSVSeries>
352+
* <file>CSV</file>
353+
* <label></label>
354+
* <fileType>csv</fileType>
355+
* <inclusionFlag>OFF</inclusionFlag>
356+
* <exclusionValues></exclusionValues>
357+
* <url></url>
358+
* <displayTableFlag>false</displayTableFlag>
359+
* </hudson.plugins.plot.CSVSeries>
360+
* <hudson.plugins.plot.XMLSeries>
361+
* <file>XML</file>
362+
* <label></label>
363+
* <fileType>xml</fileType>
364+
* <xpathString></xpathString>
365+
* <url></url>
366+
* <nodeTypeString>NODESET</nodeTypeString>
367+
* </hudson.plugins.plot.XMLSeries>
368+
* </series>
369+
* <group></group>
370+
* <numBuilds></numBuilds>
371+
* <csvFileName></csvFileName>
372+
* <csvLastModification></csvLastModification>
373+
* <style></style>
374+
* <useDescr></useDescr>
375+
* </hudson.plugins.plot.Plot>
376+
* </plots>
377+
* </hudson.plugins.plot.PlotPublisher>
378+
*/
379+
void plotBuildData(Closure plotsClosure) {
380+
381+
PlotsContext plotsContext = new PlotsContext()
382+
ContextHelper.executeInContext(plotsClosure, plotsContext)
383+
384+
NodeBuilder nodeBuilder = NodeBuilder.newInstance()
385+
386+
Node plotsNode = nodeBuilder.'hudson.plugins.plot.PlotPublisher' {
387+
plots {
388+
plotsContext.plots.each { PlotContext plot ->
389+
'hudson.plugins.plot.Plot' {
390+
group plot.group
391+
csvFileName plot.dataStore
392+
style plot.style
393+
series {
394+
plot.dataSeriesList.each { PlotSeriesContext data ->
395+
"hudson.plugins.plot.${data.type}" {
396+
file data.file
397+
label data.label
398+
fileType data.fileType
399+
}
400+
}
401+
}
402+
}
403+
}
404+
}
405+
}
406+
407+
publisherNodes << plotsNode
408+
}
409+
339410
/**
340411
* <htmlpublisher.HtmlPublisher>
341412
* <reportTargets>

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/publisher/PublisherContextSpec.groovy

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,4 +2992,62 @@ class PublisherContextSpec extends Specification {
29922992
then:
29932993
thrown(IllegalArgumentException)
29942994
}
2995+
2996+
def 'call plotPlugin with some basic args'() {
2997+
when:
2998+
context.plotBuildData {
2999+
plot('some.csv', 'my group') {
3000+
propertiesFile('data.prop')
3001+
}
3002+
}
3003+
3004+
then:
3005+
with(context.publisherNodes[0]) {
3006+
name() == 'hudson.plugins.plot.PlotPublisher'
3007+
3008+
with(plots.'hudson.plugins.plot.Plot'[0]) {
3009+
group[0].value() == 'my group'
3010+
csvFileName[0].value() == 'some.csv'
3011+
style[0].value() == 'line'
3012+
3013+
with(series[0].'hudson.plugins.plot.PropertiesSeries'[0]) {
3014+
file[0].value() == 'data.prop'
3015+
label[0].value() == ''
3016+
fileType[0].value() == 'properties'
3017+
}
3018+
}
3019+
}
3020+
}
3021+
3022+
def 'call plotPlugin with all chart styles'() {
3023+
when:
3024+
context.plotBuildData {
3025+
plot('some.csv', 'my group') {
3026+
style(chart)
3027+
propertiesFile('data.prop') {
3028+
label('some label')
3029+
}
3030+
}
3031+
}
3032+
3033+
then:
3034+
with(context.publisherNodes[0]) {
3035+
name() == 'hudson.plugins.plot.PlotPublisher'
3036+
3037+
with(plots.'hudson.plugins.plot.Plot'[0]) {
3038+
group[0].value() == 'my group'
3039+
csvFileName[0].value() == 'some.csv'
3040+
style[0].value() == chart
3041+
3042+
with(series[0].'hudson.plugins.plot.PropertiesSeries'[0]) {
3043+
file[0].value() == 'data.prop'
3044+
label[0].value() == 'some label'
3045+
fileType[0].value() == 'properties'
3046+
}
3047+
}
3048+
}
3049+
3050+
where:
3051+
chart << ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', 'stackedbar', 'stackedbar3d', 'waterfall']
3052+
}
29953053
}

0 commit comments

Comments
 (0)