Load Jenkins Pipeline Shared Library from same repository

前端 未结 7 2132
北恋
北恋 2021-01-31 07:52

TL;DR Is there a way to import code into the Jenkinsfile from the local repository (other than the load step)?

Why?

I\'ve ex

相关标签:
7条回答
  • 2021-01-31 08:55

    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.

    0 讨论(0)
提交回复
热议问题