feat: Add new command to run Pipeline Triggers
Description
There is two ways (two API endpoints) to run pipelines :
The 2nd way is useful to trigger a pipeline without any API key. Uses cases include:
- trigger a pipeline via a webhook
- trigger a pipeline via another project's CI, by using the
CI_JOB_TOKEN
env variable as a trigger token
I added the command ci run-trig
which runs a pipeline trigger.
This command is very similar to ci run
. The differences are:
- There is no
--variables-env
,--variables-file
, or--variables-from
, just--variable
because this API endpoint doesn't have thevariables[].variable_type
field. - A new option
--token
to provides the trigger token. It can be omitted if provided via theCI_JOB_TOKEN
env variable (useful in CI).
About the naming. I would have liked to name it ci trigger
but it was already taken. Command names are a bit confusing:
-
ci run
: create a pipeline -
ci run-trig
: run a pipeline trigger -
ci trigger
: re-play a job
I thought about adding this feature into the already existing command ci run
, and let the tool choose the API endpoint based on the presence of --token
, but there is multiple issues with that:
- the
variables[].variable_type
discrepancies between the two endpoints - I like the possibility to omit the token when the
CI_JOB_TOKEN
env variable is set
I don't see a perfect solution. Your feedback is welcomed.
How has this been tested?
- created a project
test-trig
with a "Hello, World!" CI - allowed my fork to trigger pipelines on
test-trig
:test-trig project > Settings > CI/CD > Token Access
- temporary modified my fork's CI to run
glab ci run-trig -b main --repo Cl00e9ment/test-trig
-
test-trig
's pipeline successfully ran - removed the authorization
- re-ran the job
- job failed as expected
I also added unit tests inspired from the ci run
's unit tests.
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms) -
Test gap