Global external library to be shared across all pipelines jobs
In order to share some common pipeline scripts, we use this common shared library Internally in Jenkins, this library is called AL
Every pipeline job will implicitly load this library from the master branch. At the top of pipeline jobs, you will see a line like
Loading library AL@master
All the files under the vars
directory are exported as global objects using the filename.
Example: if you have files called rez.groovy
and algit.groovy
, then you will have those available to use in your pipeline scripts, for example
rez.functionName()
rez.atrribure
algit.functionName()
In order to add/remove/modify pipeline scripts, it is highly advisable that you do that from a branch and go thru the code review process before merging the changes into master
since that will affect all Jenkins pipeline jobs.
Create a branch of this repo and then, in your pipeline script, try it by adding the following lines:
@Library('LIBRARY_NAME@BRANCH_NAME') _
i.e
@Library('AL@DT1659_support_for_documentation') _
Note the library will accept any Git Reference, not just a a BRANCH_NAME
for example it can be a tag
a SHA
or a Reference opearation
(i.e HEAD^
to get previous commit )
- While developing it is quite useful to use the
Replay
function. This will let you modify the pipeline code in place and try it without saving it. This is accessible fromhttp://hudson:8081/hudson/job/JOB_NAME/JOB_NUMBER/replay/
- You can see the documentation of the global objects (including the one defined in this library) In this page
http://hudson:8081/hudson/JOBNAME/pipeline-syntax/globals
- Use the declarative pipeline linter to validate your Jenkinsfile
curl -X POST -F "jenkinsfile=<Jenkinsfile" http://hudson:8081/hudson/pipeline-model-converter/validate
- Declarative pipelines cheat sheet
- The top ten best practices for pipelins
- Some tips for groovy and pipeline
- groovy documentation
See more about shared libraries here