Pipeline Hook should contain a value to determine what started the pipeline
Problem to solve
There is currently no way for pipeline webhook to determine what started the pipeline.
A scheduled pipeline payload will be identical to one triggered by a push, and a pipeline webhook payload does not contain any indicator as to what started the pipeline.
Intended users
Webhook developpers extending GitLab to fit external processes.
Further details
There are many ways to start a pipeline; all these methods are avaiable as a filter in a gitlab-ci file in the when
stanza. cf. https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic
Unfortunatly, when receiving the json payload of a pipeline webhook, there is no way to determine why it was launched in the first place. An example payload for a (failed) pipeline webhook:
"object_kind": "pipeline",
"object_attributes": {
"id": 30249,
"ref": "master",
"tag": false,
"sha": "ec0100d49400847ed069d0bc1d375c10e6747c7e",
"before_sha": "0000000000000000000000000000000000000000",
"status": "failed",
"detailed_status": "failed",
"stages": [],
"created_at": "2019-08-28 11:36:12 UTC",
"finished_at": "2019-08-28 11:36:41 UTC",
"duration": 28,
"variables": []
},
We do notice a when
clause in the .builds[] stanza, but I found it always equal to on_success
, and it seems that it corresponds to the new 'rules' https://docs.gitlab.com/ee/ci/yaml/#rules
Proposal
Add a new key in Pipeline object_attributes
such as "when": "schedule"
, "when": "push"
, "when": "web"
mirroring the values that are available in gitlab-ci.yml.
Workaround
The only workaround I found for figuring out if a pipeline is scheduled build does have two shortcomings:
- it has to be the last pipeline launched by the scheduled pipeline.
- a scheduled pipeline started with the "play" button will be considered as being the same as one started by the cron job.
In pseudo code:
when pipeline hook received:
for each scheduled pipeline configured in project:
if scheduled pipeline last pipeline id == pipeline hook pipeline id, then
return pipeline was run as a scheduled id.
Documentation
- https://docs.gitlab.com/ee/api/pipelines.html
- https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic
- https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#pipeline-events