Pipeline load and load from git

本文介绍如何在 Jenkins Pipeline 中使用 Groovy 脚本文件,并演示从本地和 Git 仓库加载脚本的方法。通过示例展示了定义函数并在 Pipeline 中调用的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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() } 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值