John Li's Blog Site

Gitlab CI Pipeline Trigger

April 20, 2019

Triggering pipelines through the API

You can add a new trigger by going to your project's Settings ➔ CI/CD under Triggers. The Add trigger button will create a new token which you can then use to trigger a rerun of this particular project's pipeline. Every new trigger you create, gets assigned a different token which you can then use inside your scripts or .gitlab-ci.yml. You also have a nice overview of the time the triggers were last used.

Taking ownership of a trigger

Each created trigger when run will impersonate their associated user including
their access to projects and their project permissions.
You can take ownership of existing triggers by clicking Take ownership.
From now on the trigger will be run as you.

Making use of trigger variables

You can pass any number of arbitrary variables in the trigger API call and they
will be available in GitLab CI so that they can be used in your .gitlab-ci.yml

For example:

Consider the following .gitlab-ci.yml where we set three stages and the uploadpackage job is run only when all jobs from the test and build stages pass. When the UPLOADTO_S3 variable is non-zero, make upload is run.

- test
- build
- package

  stage: test
  - make test

  stage: build
  - make build

  stage: package
  - if [ -n "${UPLOAD_TO_S3}" ]; then make upload; fi

You can then trigger a rebuild while you pass the UPLOADTOS3 variable and the script of the upload_package job will run:

curl --request POST \
  --form token=TOKEN \
  --form ref=master \
  --form "variables[UPLOAD_TO_S3]=true" \

or via http query string: ???

You can also supply variables too when run pipeline manually pipeline variables

And more information about GitLab Webhooks

Another GitLab premium feature is Multi-project pipelines

John Li

John Li's stuff for work, study and social activities

You can follow him on Twitter