Jenkins管道接连触发 [英] Jenkins pipelines trigger one after another

查看:57
本文介绍了Jenkins管道接连触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以执行来自Jenkins的一个管道,并使用来自先前管道的输入数据触发另一个管道吗?如果是,请您告诉我如何?

Can we execute one pipeline from Jenkins and trigger another pipeline with inputdata from previous pipeline? If Yes, will you please provide me how?

推荐答案

是的,您可以这样做.假设有两个管道,即 jobA jobB .让我们假设 jobA jobB 的上游管道,即jobB将由具有参数(或来自jobA的输入参数)的jobA调用或构建.

Yes, you can do that. Let’s say there are two pipeline i.e. jobA and jobB. Let us assume jobA is the upstream pipeline for jobB i.e. jobB will be called or build by jobA with parameters (or input parameters from jobA).

请按照以下步骤操作:

1)创建上游管道作业A和下游管道作业B(将由jobA调用)

1) create both upstream pipeline jobA and downstream piepeline jobB (which will be called by jobA)

2)在 jobB 中,选中配置页面中的此项目已参数化"框.

2) In jobB, Check the box "This project is parameterized" in configure page.

3)单击添加参数"下拉列表,然后选择字符串参数".

3) Click on Add Parameter drop-down and select String Parameter.

4)填写名称,默认值和描述.

4) Fill in the name, default value and description.

5)单击应用并保存".

5) Click on Apply and Save.

6)转到管道 jobA .创建一个类似于下面在您的Jenkinsfile或Pipeline中作为代码部分给出的阶段的阶段.

6) Go to the pipeline jobA. Create a stage similar to the stage given below in your Jenkinsfile or Pipeline as a code section.

pipeline {
     agent any
     stages {

     stage ('Build JobB')
     {
        steps {
            build job: 'jobB', parameters: [string(name: ‘Environment', value: "production")]
        }
    }
 }
}

通过这种方式,您可以一个接一个地触发Jenkins管道.

In this way, you can trigger Jenkins pipeline one after another.

注意: :我已使用声明性管道作为示例代码.如果您拥有脚本化管道或自由式项目,请按照步骤进行直到第5步,并根据您的管道更改第6步.

Note: I have use declarative pipeline as code for the example. If you have, scripted pipeline or freestyle project, follow the steps upto step 5 and change the step 6 according to your pipeline.

这篇关于Jenkins管道接连触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆