Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1046 from abayer/jenkins-41334
[JENKINS-41334] Add parallel stages documentation
  • Loading branch information
R. Tyler Croy committed Sep 25, 2017
2 parents ee9271b + 7009b16 commit 4c98e01
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
50 changes: 50 additions & 0 deletions content/doc/book/pipeline/shared-libraries.adoc
Expand Up @@ -621,3 +621,53 @@ library sources will not be checked out again.)

_Replay_ is not currently supported for trusted libraries.
Modifying resource files is also not currently supported during _Replay_.

=== Defining Declarative Pipelines

Starting with Declarative 1.2, released in late September, 2017, you can define
Declarative Pipelines in your shared libraries as well. Here's an example,
which will execute a different Declarative Pipeline depending on whether the
build number is odd or even:

[source,groovy]
----
// vars/evenOrOdd.groovy
def call(int buildNumber) {
if (buildNumber % 2 == 0) {
pipeline {
agent any
stages {
stage('Even Stage') {
steps {
echo "The build number is even"
}
}
}
}
} else {
pipeline {
agent any
stages {
stage('Odd Stage') {
steps {
echo "The build number is odd"
}
}
}
}
}
}
----

[source,groovy]
----
// Jenkinsfile
@Library('my-shared-library') _
evenOrOdd(currentBuild.getNumber())
----

Only entire `pipeline`s can be defined in shared libraries as of this time.
This can only be done in `vars/*.groovy`, and only in a `call` method. Only one
Declarative Pipeline can be executed in a single build, and if you attempt to
execute a second one, your build will fail as a result.
52 changes: 52 additions & 0 deletions content/doc/book/pipeline/syntax.adoc
Expand Up @@ -899,6 +899,58 @@ pipeline {
// Script //
----

=== Parallel

Stages in Declarative Pipeline may declare a number of nested stages within
them, which will be executed in parallel. Note that a stage must have one and
only one of either `steps` or `parallel`. The nested stages cannot contain
further `parallel` stages themselves, but otherwise behave the same as
any other `stage`. Any stage containing `parallel` cannot contain `agent` or
`tools`, since those are not relevant without `steps`.

[[parallel-stages-example]]
===== Example

[pipeline]
----
// Declarative //
pipeline {
agent any
stages {
stage('Non-Parallel Stage') {
steps {
echo 'This stage will be executed first.'
}
}
stage('Parallel Stage') {
when {
branch 'master'
}
parallel {
stage('Branch A') {
agent {
label "for-branch-a"
}
steps {
echo "On Branch A"
}
}
stage('Branch B') {
agent {
label "for-branch-b"
}
steps {
echo "On Branch B"
}
}
}
}
}
}
// Script //
----

[[declarative-steps]]
=== Steps

Expand Down

0 comments on commit 4c98e01

Please sign in to comment.