问题
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 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.
回答1:
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:
1 Using 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
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.
This can be done if you have automatic builds for projects B and C (using a .gitlab-ci.yml
file for instance).
2 Using a webhook
You can add a webhook to projects B and C through the settings/integrations page of those projects.
Simply add the following webhook on push events:
<gitlab_url>/api/v3/projects/1/ref/REF_NAME/trigger/builds?token=TOKEN
Where TOKEN and REF_NAME are the same as above.
来源:https://stackoverflow.com/questions/42837887/trigger-a-build-on-a-project-when-a-commit-pushes-to-another-project