如何远程触发Jenkins多分支管道项目的构建? [英] How to remotely trigger Jenkins multibranch pipeline project build?

查看:251
本文介绍了如何远程触发Jenkins多分支管道项目的构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题主要是这样说的。如何从远程git存储库触发Jenkins多分支管道项目构建?



触发器远程构建构建触发器选项似乎不起作用,因为没有令牌你设置的是保存的。

解决方案

目前(Jenkins 2.22)触发器远程构建构建触发器选项在多分支管道作业配置,但不起作用(如果您检查它并指定一个标记,则无论如何它都会被重置)。根据,故意触发器无法设置,但是一个bug它根本就是一种选择。

在同一个线程中,他们解释了如何触发多分支管道项目中每个单独项目(分支)的构建。我需要的是一个动态设置,它可以用于设置触发器后创建的分支,而不是来自线程的建议端点( / job / project-name / job-name / build ,它应该是 / job / job-name / project-name / build ,因为项目是从作业中的分支创建的),我发现要使用的端点是 / job / job-name / build 。为了实现上述目标,您必须创建一个带有API令牌的用户(转到管理Jenkins - >管理用户 - >齿轮图标 - >显示API令牌),并在请求中使用这些用户名和密码。



对于那些曾经使用Jenkins REST API的人来说,解决方案可能是显而易见的,但是当您对多分支管道项目和REST API都不熟悉时, 。


Title mostly says it. How can you trigger a Jenkins multibranch pipeline project build from a remote git repository?

The "Trigger builds remotely" build trigger option does not seem to work, since no tokens that you set are saved.

解决方案

At the moment (Jenkins 2.22) the "Trigger builds remotely" build trigger option is visible in the multibranch pipeline job configuration, but does not work (if you check it and specify a token, it gets reset after saving anyway). According to this, it is intentional that the trigger cannot be set, but a bug that it appears as an option at all.

In the same thread they explain how to trigger builds for each individual project (branch) in a multibranch pipeline project. What I needed was a dynamic setup that would work for branches created after setting up the trigger, so rather than the suggested endpoint from the thread (/job/project-name/job-name/build, which should have been /job/job-name/project-name/build , since projects are created from branches in a job), I found that the endpoint to use is /job/job-name/build. In order for that to work you have to create a user with an API token (go to Manage Jenkins -> Manage Users -> Gear icon -> Show API Token), and use those as username and password in your request.

The solution might be obvious for those used to working with Jenkins REST API, but when you are new to both multibranch pipeline projects and the REST API, it doesn't hurt to be explicit.

这篇关于如何远程触发Jenkins多分支管道项目的构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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