Skip to content
Permalink
Browse files

Add Libraries to Jenkins Pipelines

Pipelines can now load groovy files that are located in buildscripts/scripts/

To enable loading of libraries copy code from buildscripts/scripts/vars/jenkins-template.groovy to the top of your pipeline script.
Don't edit this code inside of the pipeline, only in the template. To copy updates to the Pipelines call vars/update-jenkins-lib-loading.sh from inside buildscripts/scripts

Change-Id: I9d2fcaa43ebf130130e61540bf08868c1d0b3c76
  • Loading branch information
AZurhake committed Nov 28, 2019
1 parent a91f9ce commit 01b7a1d24338468521f46650d70759334c16d723
@@ -0,0 +1,21 @@
// The following code adds libraries to the Pipeline script
// Functions from libraries can be run by calling file-basename.functionaname()
// If you need to adjust the loading of the library, please code your changes in
// buildscripts/scripts/ on file jenkins-lib-loader/jenkins-template.groovy and run
// jenkins-lib-loader/update-jenkins-lib-loading.sh
// check the results and commit
node {
stage('Load Jenkins Libs') {
def LIB = [
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'vars'],
[path: 'buildscripts/scripts/vars']]],
[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: true]],
userRemoteConfigs: scm.userRemoteConfigs
]
library identifier: 'jenkins-libs@version', retriever: legacySCM(LIB)
}
}
// jenkins-libs loaded
@@ -0,0 +1,15 @@
#!/bin/bash

# This script updates the loading of the library
# The file jenkins-lib-loader/jenkins-template.groovy is used
# Only jenkins files, that already load the library are affected
# Please check the changes in git and commit them

for FILE in *.jenkins; do
if $(grep '^// jenkins-libs loaded' $FILE > /dev/null); then
sed -i '0,/^\/\/ jenkins-libs loaded$/d' $FILE
cat jenkins-lib-loader/jenkins-template.groovy > $FILE.tmp
cat $FILE >> $FILE.tmp
mv $FILE.tmp $FILE
fi
done
No changes.
1 vars

0 comments on commit 01b7a1d

Please sign in to comment.
You can’t perform that action at this time.