The following post is example of how to activate and use Trigger pipeline by API the official documentation over here as it mentioned is can be use “to trigger a pipeline for a specific branch or tag”; for our example I use it to activate a pipeline into specific branch.
Steps:
repoA will be the main one where the pipeline trigger it will be activate
- From repoA go to Settings-CI/CD-Pipeline triggers
- Click on “add trigger” copy your token
- From repoB that will be our caller of the repoA pipeline create a variable where you can paste the token.
- Finally into your pipeline on repoB you can add something like below:
The best part is that you can reference to specific branch ref="<branch_name>".
trigger:
# Trigger to <project> project ID: <>
before_script:
- apt-get update
- apt-get install -y curl
script:
- 'curl -X POST --fail -F token="$MY_TRIGGER_TOKEN" -F ref="<branch_name>" https://gitlab.<company>/api/v4/projects/<id>/trigger/pipeline'
NOTE: from my gitlab server my runners are ubuntu 16.
hope the above example can be useful.