Search code examples
gitlabyamlgitlab-ci

gitlab ci workflow rules


The below example from gitlab is working while my code is not working. I am using similar logic. Please suggest.

Gitlab code -

variables:
  PROJECT1_PIPELINE_NAME: 'Default pipeline name'  # A default is not required.

workflow:
  name: '$PROJECT1_PIPELINE_NAME'
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      variables:
        PROJECT1_PIPELINE_NAME: 'MR pipeline: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME'
    - if: '$CI_MERGE_REQUEST_LABELS =~ /pipeline:run-in-ruby3/'
      variables:
        PROJECT1_PIPELINE_NAME: 'Ruby 3 pipeline'
    - when: always  # Other pipelines can run, but use the default name

My code -

variables:
  PIPELINE_NAME: "default"
workflow:
  name: '$PIPELINE_NAME'
  rules:
    - if: '$APPLICATION_ID == ""'
      variables:
        PIPELINE_NAME: '$ACCESS_TYPE-$ROLE_DEFINATION-$GITLAB_USER_EMAIL'
    - if: '$APPLICATION_ID'
      variables:
        PIPELINE_NAME: '$ACCESS_TYPE-$APPLICATION_ID-$GITLAB_USER_EMAIL'

Solution

  • Got the error . The issue of pipeline name not desplaying is because I was using a gitlab variable - PIPELINE_NAME.

    I changed my code to use PROJECT1_PIPELINE_NAME. And it worked.

    workflow:
      name: '$PROJECT1_PIPELINE_NAME'
      rules:
        - if: '$APPLICATION_ID == ""'
          variables:
            PROJECT1_PIPELINE_NAME: '$ACCESS_TYPE-$ROLE_DEFINATION-$GITLAB_USER_EMAIL'
        - if: '$APPLICATION_ID'
          variables:
            PROJECT1_PIPELINE_NAME: '$ACCESS_TYPE-$APPLICATION_ID-$GITLAB_USER_EMAIL'