Search code examples
gitgithubcontinuous-integrationgitlabgitlab-ci

How to get Gitlab merge request description in Gitlab CI?


I want to fetch the description of the merge request to generate changelog. Is it possible to get the description??


Solution

  • In GitLab CI/CD's predefined environment variables there are some variables related to merge requests, such as:

    CI_MERGE_REQUEST_ASSIGNEES
    CI_MERGE_REQUEST_CHANGED_PAGE_PATHS
    CI_MERGE_REQUEST_CHANGED_PAGE_URLS
    CI_MERGE_REQUEST_ID
    CI_MERGE_REQUEST_IID
    CI_MERGE_REQUEST_LABELS
    CI_MERGE_REQUEST_PROJECT_PATH
    CI_MERGE_REQUEST_PROJECT_URL
    CI_MERGE_REQUEST_REF_PATH
    CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
    CI_MERGE_REQUEST_SOURCE_PROJECT_ID
    CI_MERGE_REQUEST_SOURCE_PROJECT_PATH
    CI_MERGE_REQUEST_SOURCE_PROJECT_URL
    CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    CI_MERGE_REQUEST_TARGET_BRANCH_SHA
    CI_MERGE_REQUEST_TITLE
    CI_MERGE_REQUEST_EVENT_TYPE
    
    ⋮
    

    You can easily access them inside pipelines and jobs.


    EDIT:
    It seems there is no variable to access the merge requests description. I think using GitLab's Merge requests API can be helpful. So by requesting below URL inside your pipeline (using curl or other tools) you will get access to more information about a single merge request:

    GET    $CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID