'Find a source and target branch name

I have a stage in my ci-cd pipeline:

version_check:main:
  stage: main
  script:
    - echo CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    - echo CI_MERGE_REQUEST_TARGET_BRANCH_NAME=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME

and the output in CI log is:

$ echo CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=
$ echo CI_MERGE_REQUEST_TARGET_BRANCH_NAME=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
CI_MERGE_REQUEST_TARGET_BRANCH_NAME=

how can I get source and destination branch name in proper way?



Solution 1:[1]

version_check:main:
  stage: main
  only:
    - merge_request
  script:
    - echo ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}
    - echo ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}

the output is:

$ echo ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}
ALXX3-2663
$ echo ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
master

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a11eksandar