Stay Hungry,Stay Foolish!

Pipeline load and load from git

load

https://www.sourcefield.nl/post/jenkins-pipeline-tutorial/

 

 

node {
    // Use the shell to create the file 'script.groovy' 
    sh '''echo '
    def hello(name) {
        echo "Hello ${name} from script" 
    }
    return this
    ' > script.groovy'''
    def script = load 'script.groovy'
    script.hello('Roy')
}

 

 

load from git

 

Loading a script from another Git repository

This requires the Pipeline Remote File Loader plugin. The example assumes you have a repository somewhere that contains a Pipeline.groovy file, which you want to download to your Jenkins workspace.

  1. Go to Manage Jenkins > Manage Plugins and install Pipeline Remote File Loader (without restart)

  2. Configure a Pipeline job and set the Pipeline script to the following:

 

node {
    stage 'Load pipeline script'
    def pipeline = fileLoader.fromGit(
        'Pipeline.groovy', 
        'https://bitbucket.org/your-account/your-build-scripts.git', 
        'master', // use a branch or tag
        'your-account-credential-id', // ID from Credentials plugin
        ''
    ) 
    checkout scm
    pipeline.execute()
}    

 

posted @ 2018-04-05 23:44  lightsong  阅读(802)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel