Add pipeline status subscription
What does this MR do and why?
The purpose of this MR is to implement a subscription for front end views to be able to access real time updates on a pipeline status. This will initially be used for real time updates on the pipeline status icon in the latest commit widget on the main repository page.
-
ciPipelineStatusUpdatedrequires a global pipeline id to initiate the subscription. - the subscription is triggered when any transition event occurs on the pipeline's status
- the subscription payload is a Ci::PipelineType
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Example Subscription query:
subscription pipelineStatusUpdated($pipelineId: CiPipelineID!) {
ciPipelineStatusUpdated(pipelineId: $pipelineId) {
iid
status
detailedStatus {
detailsPath
name
tooltip
label
favicon
}
}
}
NOTE: You will need to set a pipelineId variable or you can pass it directly. The value required is a pipeline gid( ie. "gid://gitlab/Ci::Pipeline/1234"). You can also get the pipeline's formatted gid in the rails console by calling to_gid on an existing pipeline.
Steps to test and validate locally:
- Ensure you are logged into your local instance and navigate to the graphql explorer page (eg. http://gdk.test:3000/-/graphql-explorer or relace
gdk.test:3000to whatever your localhost is set to) - In your terminal start a rails console (
bundle exec rails c) - In the console find a pipeline you would like to use for testing and fetch the global id:
pipeline = Ci::Pipeline.last
pipeline.to_gid.uri.to_str #this is the string you will use for the $pipelineId variable in the graphql UI
- Return to the graphql explorer and copy the query noted above
⬆️ before the steps - Set the pipelineId variable to the global id string you generated in the console in Step#3 (you can do this either directly in the subscription query or in the section below the query box that allows you to input variables:
{
"pipelineId": "gid://gitlab/Ci::Pipeline/???" #replace with the string you generated in the console
}
- Press the play
▶️ in the graphql-explorer UI. The initial response should be nil because you are initiating/opening up the subscription. You should see this response:
{
"data": {
"ciPipelineStatusUpdated": null
}
}
- There are 2 ways to trigger the subscription from the rails console to test it out. Using the same pipeline set earlier (
pipeline = Ci::Pipeline.last) :
i. Triggering the subscription directly: GraphqlTriggers.ci_pipeline_status_updated(pipeline)
ii. Mocking a pipeline state machine event with any valid action(depending on the current state of your pipeline the actual status may update or not): pipeline.cancel!
- With either of the actions performed in Step#7 the subscription response should update with the values you set in the subscription and the data response should look something like:
{
"data": {
"ciPipelineStatusUpdated": {
"iid": "40",
"status": "CANCELED",
"detailedStatus": {
"detailsPath": "/gitlab-org/gitlab-shell/-/pipelines/571",
"name": "CANCELED",
"tooltip": "canceled",
"label": "canceled",
"favicon": "favicon_status_canceled"
}
}
}
}
Gotchas: If you are getting and unauthorized error make sure the user you are logged in as is authorized to read the pipelien/project, probably best to be logged in as the root user.
Related to #516247 (closed)


