How make a if statement in the CI file

Hi,

I’m afraid, this is not possible in the relatively static YAML configuration language. I would write a small bash script which reads the environment variables CI_MERGE_REQUEST_ID and does the printing then. Whenever the ID is filled with content, this is a merge request.

vim run.sh

#!/bin/bash

if [ "$CI_MERGE_REQUEST_ID" != "" ]; then
  echo "Test"
fi

Before adding that to your CI config, you can test it locally.

CI_MERGE_REQUEST_ID=42 bash run.sh

Add the script into the main directory, or yet better, in a dedicated sub directory.

mkdir -p .gitlab/ci
vim .gitlab/ci/run.sh

chmod +x .gitlab/ci/run.sh
git add .gitlab/ci/run.sh
git commit -v

Then add it to your CI job config.

vim .gitlab-ci.yml

myjob:
  script:
  - ./.gitlab/ci/run.sh

Cheers,
Michael