当提交推送到另一个项目时,触发一个项目的构建 [英] trigger a build on a project when a commit pushes to another project
问题描述
我在gitlab上使用gitlab-runner机器有三个项目A,B,C.项目A包含gitlab-ci.yml文件,当对A进行提交时,该文件将调用脚本来构建程序:
I have three projects A,B,C on gitlab with a gitlab-runner machine. Project A contains gitlab-ci.yml file which calls a script to build the program when there is a commit on A:
build:
stage: build
script:
- ./build-platform.sh
A取决于B和C项目.当对B或C进行提交时,如何在A上触发构建.我无法将B,C放在A中,也无法轻松地将build-platform.sh转换为gitlab-ci.yml文件语法.
A depends on B and C projects. How can I trigger a build on A when there is a commit on B or C. I cannot put B,C in A and I cannot convert build-platform.sh to a gitlab-ci.yml file syntax easily.
推荐答案
有两种方法可以完成所需的工作,但它们都依赖于您在gitlab中投影A的设置并添加触发器令牌.单击 Triggers 部分中的Add trigger
,可通过<project A's gitlab URL>/settings/ci_cd
页完成此操作.
There's a couple ways of doing what you want, but they all rely on you going to project A's settings in gitlab and adding a trigger token. This is done through the <project A's gitlab URL>/settings/ci_cd
page by clicking on Add trigger
in the Triggers section.
您还将从该页面中找到使用该触发令牌的不同方式.
You will also find the different ways of using that trigger token from that page.
出于完整性考虑,以下是其中提到的几种方法:
For the sake of completeness here's a few of the ways mentioned there:
如果您可以在项目B或C的构建结束时使用curl,则只需添加以下内容:
If you can use curl at the end of the build of projects B or C then simply add the following:
curl -X POST \
-F token=TOKEN \
-F ref=REF_NAME \
<gitlab_url>/api/v3/projects/1/trigger/builds
TOKEN是您刚刚为项目A生成的触发令牌,REF_NAME是要为其运行构建的分支或标记的名称.
Where TOKEN is the trigger token you just generated for project A and REF_NAME is the name of a branch or tag to run the build for.
如果您具有针对项目B和C的自动构建(例如,使用.gitlab-ci.yml
文件),则可以完成此操作.
This can be done if you have automatic builds for projects B and C (using a .gitlab-ci.yml
file for instance).
您可以通过项目B和C的设置/集成页面为其添加Webhook.
You can add a webhook to projects B and C through the settings/integrations page of those projects.
只需在推送事件上添加以下webhook:
Simply add the following webhook on push events:
<gitlab_url>/api/v3/projects/1/ref/REF_NAME/trigger/builds?token=TOKEN
TOKEN和REF_NAME与上面的相同.
Where TOKEN and REF_NAME are the same as above.
这篇关于当提交推送到另一个项目时,触发一个项目的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!