TL;DR Is there a way to import code into the Jenkinsfile
from the local repository (other than the load
step)?
I\'ve ex
I found the version from Pawel has problems if you are checking out the pipeline from SCM (not embedded in Jenkins job UI config). This is my version for those cases:
node {
def scriptFolder = sh(script: "echo \$(pwd | sed 's,\\(.*\\)\\(@[0-9]*\$\\),\\1,')@script/\$(sed -n '2,\$p' ../config.xml | xmllint --xpath '(//scriptPath/text())' - | xargs dirname)", returnStdout: true).trim()
sh("cd ${scriptFolder} && ls -l vars/ && if [ -d .git ]; then rm -rf .git; fi; git init && git add --all . && git commit -m init &> /dev/null")
library identifier: 'local-lib@master', retriever: modernSCM([$class: 'GitSCMSource', remote: scriptFolder])
stage('Build') {
log.info("called shared lib") // use the loaded library
}
}
For these cases, the pipeline itself is checkout out in a different workspace (same directory name but with @script
in the name) than what the pipeline itself defines.