This project is a Shared Library with common utility functions for building your own Jenkins pipelines.
There are two possible ways to reference this library in your own pipeline:
- Using a direct reference to this library on GitHub. Add the following annotation
to the top of your
Jenkinsfile
:Please note the trailing underscore! Instead of referencing master you can (and actually should) fix the dependency on a specific tag or commit hash.@Library('github.com/moxio/jenkins-pipeline-utils@master') _
- By adding this library as a global pipeline library to your Jenkins instance.
Go to
Manage Jenkins > Configure System > Global Pipeline Libraries
and add this library using a reference to its GitHub repository and a name of your choice (e.g.moxio-pipeline-utils
). You can then either checkLoad implicitly
to make the library available by default, or reference it explicitly by its name at the top of yourJenkinsfile
:Again, note the trailing underscore.@Library('moxio-pipeline-utils') _
The library defines the following functions:
Checks out code from the SCM and ensures a clean working copy state: any local modifications are rolled back and unversioned files are deleted. Supports both subversion and git. In case of a git repository, any git hooks configured in the local checkout are cleaned up as well.
You can use the function by calling cleanCheckout scm
as a drop-in replacement
for the default checkout scm
step. You probably want to use skipDefaultCheckout()
in your pipeline options {}
block to prevent Jenkins from already checking out
the code using the 'default' checkout
by itself.
Alternative for the built-in fileExists
that only returns true if the path
actually represents a directory.
In your own shared pipeline library, this function gets a shell script from the
resources/
directory, makes it available and executable locally, and returns
a path by which it can be executed. In essence this is a variant of libraryResource
more suitable for shell scripts.
Returns whether the current build was started by a cron trigger. This is useful for pipelines that need to perform different steps for builds triggered by SCM events (e.g. only 'light' unit tests) than for nightly builds triggered by cron (e.g. also 'heavy' integration tests).
Returns whether the given SCM corresponds to a repository hosted on gitlab.com
.
This can be useful if you want to share a default pipeline between Gitlab- and
non-Gitlab-repositories, but still update the Gitlab commit status if relevant, e.g.:
if (isGitlabRepository(scm)) {
updateGitlabCommitStatus name: 'Jenkins', state: 'failed'
}
This project adheres to Semantic Versioning.
Contributions to this project are more than welcome.
This project is released under the MIT license.
Made with love, coffee and fun by the Moxio team from Delft, The Netherlands. Interested in joining our awesome team? Check out our vacancies (in Dutch).