A Shared Library for Jenkins pipelines containing useful actions.
-
Configure the shared library in Jenkins:
- Globally: go to Manage Jenkins -> Configure System. -> Global Pipeline Libraries, add a library with the following settings:
- Single pipeline: go to [your pipeline] -> Configure -> Pipeline Libraries.
Add the following settings:
- Name:
jenkins-pipeline-library
- Default version: Specify a Git reference (branch or commit SHA), e.g.
master
- Retrieval method: Modern SCM
- Select the Git type
- Project repository:
https://github.com/Mindera/jenkins-pipeline-library.git
- Credentials: (leave blank)
-
Then create a Jenkins job with the following pipeline (note that the underscore
_
is not a typo):@Library('jenkins-pipeline-library')_ stage('Demo') { retryContinueOrAbort(description: "'Hello World'", timeoutMinutes: 1) { echo 'π€ Hello World!' } }
This will output the following from the build:
[Pipeline] stage
[Pipeline] { (Demo)
[Pipeline] echo
βοΈ Trying 'Hello World', attempt number 0.
[Pipeline] echo
π€ Hello World!
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS
You're set! π
Action that receives a closure to perform arbitrary work and on failure asks the user for input on whether to Retry, Continue, or Abort the action. It calls itself recursively on Retry, having no hard limit on the number of possible retries.
Parameter | Type | Default value | Description |
---|---|---|---|
description | String |
"action" |
description of the action (for logging purposes) |
timeoutMinutes | int |
10 |
number of minutes before timing out waiting for user input |
markAsUnstableOnContinue | bool |
true |
flag indicating whether to mark the build as "UNSTABLE" if Continue is chosen |
body | Closure |
The work to perform |
N/A
@Library('jenkins-pipeline-library')_
stage('Demo') {
retryContinueOrAbort(description: "'my awesome work'", timeoutMinutes: 1) {
echo "doing awesome work"
(...)
}
}
Action that receives a closure to perform arbitrary work but prior to running it asks the user for input on whether to Run or Skip it.
Parameter | Type | Default value | Description |
---|---|---|---|
description | String |
"action" |
description of the action (for logging purposes) |
timeoutMinutes | int |
1 |
number of minutes before timing out waiting for user input |
markAsUnstableOnSkip | bool |
true |
flag indicating whether to mark the build as "UNSTABLE" if Skip is chosen |
body | Closure |
The work to perform |
Return Type | Description |
---|---|
boolean |
true if the block was run, false otherwise (i.e. was skipped) |
@Library('jenkins-pipeline-library')_
stage('Demo') {
environment {
didRun = false
}
didRun = runOrSkip(description: "'my awesome work'", timeoutMinutes: 1) {
echo "doing awesome work"
(...)
}
script {
if (didRun) {
echo "do stuff only when awesome work is run"
(...)
}
}
}
Action that aborts a build if the current job has a newer build to execute.
N/A
N/A
@Library('jenkins-pipeline-library')_
stage('Demo') {
abortBuildIfNewerExists()
}