How do I label pipelines in GitLab?
Asked Answered
T

2

5

How do I add a label to the GitLab pipelines when they run?
This would be extremely helpful when you run a few nightly (scheduled) pipelines for different configurations on the main branch. For example, we run a nightly main branch with several submodules, each set at a point in their development (a commit point SHA) and I want to label that 'MAIN'. We run a second pipeline that I want to label 'HEADs', which is a result of pulling all of the HEAD's of the submodule to see if changes will break the main trunk when they are merged in.
Currently it shows:

  • Last commit message.
  • Pipeline #
  • commit SHA
  • Branch name
  • 'Scheduled'

That is helpful, but it is very difficult to tell them apart because only the pipeline # changes between the pipelines.

Tolerance answered 29/10, 2022 at 15:23 Comment(0)
T
8

This seems to be officially supported with GitLab 15.7 (December 2022)

Add custom names to pipelines with workflow:name:

For some projects, the same pipeline can be configured to run differently for different variables or conditions, creating very distinct outcomes for successful pipelines.
It can be hard for you to determine which version of that pipeline ran since there is no indication about the inputs used for that particular run.
While labels like scheduled and API help, it is sometimes still difficult to identify specific pipelines.

Now you can set a pipeline name using the keyword workflow:name to better identify the pipeline with string, a CI/CD variable, or a combination of both.

See Documentation and Issue.

Note:

If the name is an empty string, the pipeline is not assigned a name.
A name consisting of only CI/CD variables could evaluate to an empty string if all the variables are also empty.


And, since GitLab 16.3 (August 2023):

Expose pipeline name as a predefined CI/CD variable

Pipeline names defined with the workflow:name keyword are now accessible via the predefined variable $CI_PIPELINE_NAME.

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfhWmf0cC2nZ7-sWV9QWRft/images/16_3/workflow-name-image.png -- Expose pipeline name as a predefined CI/CD variable

See Documentation and Issue.

Tangent answered 24/12, 2022 at 10:37 Comment(0)
T
6

I have good news!!
Our friends at GitLab have been working on this feature. There is now a way to label your pipeline in release 15.5.1-ee.0!

It uses the workflow control with a new keyword name

workflow:
    name: 'Pipeline for branch: $CI_COMMIT_BRANCH'

You can even use the workflow:rules pair to have different names for you pipeline:

variables:
    PIPELINE_NAME: 'Default pipeline name'

workflow:
    name: '$PIPELINE_NAME'
rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
       variables:
           PIPELINE_NAME: 'MR pipeline: $CI_COMMIT_BRANCH'
    - if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-in-ruby3/'
       variables:
           PIPELINE_NAME: 'Ruby 3 pipeline'

Find the docs here: https://docs.gitlab.com/ee/ci/yaml/#workflow

This feature is disabled by default in 15.5 because it is so new.
You can enable the feature flag, which is named pipeline_name.

See this link to enable: https://docs.gitlab.com/ee/administration/feature_flags.html
(You need to use the Rails Console to enable it. Pretty easy.)

Note: Remember that the workflow keyword affects the entire pipeline instance.

Tolerance answered 29/10, 2022 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.