How to use Jenkins Pipeline Folder-Level Shared Library?

后端 未结 1 1975
孤独总比滥情好
孤独总比滥情好 2021-02-14 14:38

We have few components which is stored in their own git repositories. Specific combination of those components are built and delivered as solutions for different type of deploym

1条回答
  •  感情败类
    2021-02-14 15:24

    I guess that proper way to do that is to implement a custom SCMRetriever and use library step.

    However, you can use the following hack:

    Assuming jenkins/vars/log.groovy in your local repo contains:

    def info(message) {
        echo "INFO: ${message}"
    }
    

    Your Jenkinsfile can load that shared library from the jenkins/ directory using library step:

    node('node1') { // load library
        checkout scm
        // create new git repo inside jenkins subdirectory
        sh('cd jenkins && git init && git add --all . && git commit -m init &> /dev/null') 
        def repoPath = sh(returnStdout: true, script: 'pwd').trim() + "/jenkins"
        library identifier: 'local-lib@master', retriever: modernSCM([$class: 'GitSCMSource', remote: repoPath])
    }
    
    node('node2') {
        stage('Build') {
            log.info("called shared lib") // use the loaded library
        }
    }
    

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