Skip to content

Commit

Permalink
Update the parallel job example for Pipeline Model Definition Plugin …
Browse files Browse the repository at this point in the history
…v1.2 parallel stages and added test support for that. Main Jenkinsfile now creates JUnit report.
  • Loading branch information
macg33zr committed Sep 28, 2017
1 parent 798761d commit 5a1e301
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ pipeline {

post {
always {
echo 'pipeline unit tests completed'
echo 'pipeline unit tests completed - recording JUnit results'
junit 'build/reports/**/*.xml'
}

success {
Expand Down
31 changes: 30 additions & 1 deletion exampleJobs/parallel/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ pipeline {
}
}

stage('Static') {
// Pre pipeline v1.2 do it this way, awkward syntax
stage('Static Old Way') {
steps {
parallel (
'branch_1' : {
Expand All @@ -58,5 +59,33 @@ pipeline {
}
}

// From pipeline v1.2 do it this way : requires Pipeline Model Definition Plugin v1.2+
stage('Static New Way') {

// Support for full parallel stages. Nice.
parallel {

stage('Stage 1') {
steps {
echo "Running pipeline v1.2 static stage 1"
}
}

stage('Stage 2') {
steps {
echo "Running pipeline v1.2 static stage 2"
}
}

stage('Stage Skipped') {

when { expression { false } }

steps {
echo "pipeline v1.2 static stage will be skipped"
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions pipelineTests/groovy/testSupport/PipelineTestHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class PipelineTestHelper extends BasePipelineTest {
helper.registerAllowedMethod('stages', [Closure.class], null)
helper.registerAllowedMethod('validateDeclarativePipeline', [String.class], null)

helper.registerAllowedMethod('parallel', [Closure.class], null)

/**
* Handling of a stage skipping execution in tests due to failure, abort, when
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
Jenkinsfile.sh(gradle build test)
Jenkinsfile.post(groovy.lang.Closure)
Jenkinsfile.always(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests completed)
Jenkinsfile.echo(pipeline unit tests completed - recording JUnit results)
Jenkinsfile.junit(build/reports/**/*.xml)
Jenkinsfile.success(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests PASSED)
Jenkinsfile.failure(groovy.lang.Closure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
Jenkinsfile.sh(gradle clean build test -i)
Jenkinsfile.post(groovy.lang.Closure)
Jenkinsfile.always(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests completed)
Jenkinsfile.echo(pipeline unit tests completed - recording JUnit results)
Jenkinsfile.junit(build/reports/**/*.xml)
Jenkinsfile.success(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests PASSED)
Jenkinsfile.failure(groovy.lang.Closure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
Jenkinsfile.sh(gradle test)
Jenkinsfile.post(groovy.lang.Closure)
Jenkinsfile.always(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests completed)
Jenkinsfile.echo(pipeline unit tests completed - recording JUnit results)
Jenkinsfile.junit(build/reports/**/*.xml)
Jenkinsfile.success(groovy.lang.Closure)
Jenkinsfile.echo(pipeline unit tests PASSED)
Jenkinsfile.failure(groovy.lang.Closure)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Jenkinsfile.run()
Jenkinsfile.pipeline(groovy.lang.Closure)
Jenkinsfile.agent(groovy.lang.Closure)
Jenkinsfile.stages(groovy.lang.Closure)
Jenkinsfile.stage(Setup, groovy.lang.Closure)
Jenkinsfile.steps(groovy.lang.Closure)
Jenkinsfile.script(groovy.lang.Closure)
Jenkinsfile.stage(Dynamic, groovy.lang.Closure)
Jenkinsfile.steps(groovy.lang.Closure)
Jenkinsfile.script(groovy.lang.Closure)
Jenkinsfile.parallel({foo=groovy.lang.Closure, bar=groovy.lang.Closure})
Jenkinsfile.echo(Running foo branch..)
Jenkinsfile.echo(Running bar branch...)
Jenkinsfile.stage(Static Old Way, groovy.lang.Closure)
Jenkinsfile.steps(groovy.lang.Closure)
Jenkinsfile.parallel({branch_1=groovy.lang.Closure, branch_2=groovy.lang.Closure})
Jenkinsfile.echo(Running static branch 1)
Jenkinsfile.echo(Running static branch 2)
Jenkinsfile.stage(Static New Way, groovy.lang.Closure)
Jenkinsfile.parallel(groovy.lang.Closure)
Jenkinsfile.stage(Stage 1, groovy.lang.Closure)
Jenkinsfile.steps(groovy.lang.Closure)
Jenkinsfile.echo(Running pipeline v1.2 static stage 1)
Jenkinsfile.stage(Stage 2, groovy.lang.Closure)
Jenkinsfile.steps(groovy.lang.Closure)
Jenkinsfile.echo(Running pipeline v1.2 static stage 2)
Jenkinsfile.stage(Stage Skipped, groovy.lang.Closure)
Jenkinsfile.when(groovy.lang.Closure)
Jenkinsfile.expression(groovy.lang.Closure)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ class ParallelJobTestSpec extends PipelineSpockTestBase {
then:
printCallStack()
assertJobStatusSuccess()

then:
testNonRegression("Parallel_Jenkinsfile_should_complete_with_success")
}
}

0 comments on commit 5a1e301

Please sign in to comment.