Navigation Menu

Skip to content

Commit

Permalink
Preliminary doc update for JENKINS-46547
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Sep 18, 2017
1 parent b369083 commit 7009b16
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions content/doc/book/pipeline/shared-libraries.adoc
Expand Up @@ -620,3 +620,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.

0 comments on commit 7009b16

Please sign in to comment.