如何使用 GitHub Org 插件从 jenkins 管道(jenkinsfile)触发另一个作业? [英] How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?

查看:31
本文介绍了如何使用 GitHub Org 插件从 jenkins 管道(jenkinsfile)触发另一个作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Jenkinsfile 内部触发另一个作业的构建?

How can I trigger build of another job from inside the Jenkinsfile?

我假设这个工作是同一个 github 下的另一个仓库组织,一个已经拥有自己的 Jenkins 文件的组织.

I assume that this job is another repository under the same github organization, one that already has its own Jenkins file.

我也想只在分支名称是 master 时才这样做,因为触发任何本地分支的下游构建没有意义.

I also want to do this only if the branch name is master, as it doesn't make sense to trigger downstream builds of any local branches.

更新:

stage 'test-downstream'
node {
     def job = build job: 'some-downtream-job-name'
}

仍然,当我执行时,我得到一个错误

Still, when executed I get an error

未找到名为 some-downtream-job-name 的参数化作业

No parameterized job named some-downtream-job-name found

我确定该职位存在于 jenkins 中,并且与当前职位在同一组织文件夹下.这是另一个有自己的 Jenkinsfile 的工作.

I am sure that this job exists in jenkins and is under the same organization folder as the current one. It is another job that has its own Jenkinsfile.

请注意,此问题特定于 GitHub 组织插件 为您的 GitHub 组织中的每个存储库和分支自动创建和维护作业.

Please note that this question is specific to the GitHub Organization Plugin which auto-creates and maintains jobs for each repository and branch from your GitHub Organization.

推荐答案

首先,在node中包裹build步骤是浪费一个executor slot.您的上游执行程序将无缘无故地闲置.

First of all, it is a waste of an executor slot to wrap the build step in node. Your upstream executor will just be sitting idle for no reason.

其次,在多分支项目中,你可以使用环境变量BRANCH_NAME来使逻辑以当前分支为条件.

Second, from a multibranch project, you can use the environment variable BRANCH_NAME to make logic conditional on the current branch.

第三,job 参数采用绝对或相对作业名称.如果你给一个没有任何路径限定的名称,那将指的是同一文件夹中的另一个作业,在多分支项目的情况下,这意味着同一存储库的另一个分支.

Third, the job parameter takes an absolute or relative job name. If you give a name without any path qualification, that would refer to another job in the same folder, which in the case of a multibranch project would mean another branch of the same repository.

因此你想写的可能是

if (env.BRANCH_NAME == 'master') {
    build '../other-repo/master'
}

这篇关于如何使用 GitHub Org 插件从 jenkins 管道(jenkinsfile)触发另一个作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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