0

I want to create Job trigged by MERGE_REQUEST and exist force_remove_source_branch in true.

Get info about force_remove_source_branch from api

curl --header "PRIVATE-TOKEN: ${API_ACCESS_TOKEN}" "$CI_GITLAB/projects/$CI_PROJECT_ID/merge_requests/$CI_OPEN_MERGE_REQUESTS/changes" | jq -r ".force_remove_source_branch"

For gitlab api need CI_PROJECT_ID and CI_OPEN_MERGE_REQUESTS

CI_OPEN_MERGE_REQUESTS is merge_request_iid

I research much pipeline

CI_PROJECT_ID exist its OK

But I couldn't find merge_request_iid in clean variant. Only must symantec variant

WD=/builds/projects/adv/ETL/mvp
See merge request projects/adv/ETL/mvp!18

How simple get :merge_request_iid from pipeline?

1 Answer 1

0

There are a set of CI Variables that exist for Merge Request Pipelines in the Predefined Variables Documentation.

Specifically the $CI_MERGE_REQUEST_IID variable is a Predefined Variable when the Pipeline Source ($CI_PIPELINE_SOURCE) is merge_request_event, so as long as the job runs for Merge Requests pipelines, this variable will exist.

Here's an example job for a Merge Request pipeline:

Example Job:
  stage: example
  rules:
    - if: $CI_PIPELINE_SOURCE === 'merge_request_event'
      when: always
    - when: never
  script:
    - echo $CI_MERGE_REQUEST_IID # prove that the Merge Request IID exists
    - curl --header "PRIVATE-TOKEN: ${API_ACCESS_TOKEN}" "$CI_GITLAB/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/changes" | jq -r ".force_remove_source_branch"

When a job has a rules section that looks for the merge_request_event source, the job will run for Merge Request Pipelines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.