I have YAML file in my Gitlab branch. As per the requirement i want to create one random mergeID in YAML file.
22 Answers
Another simple solution without using script is to use the gitlab env variable CI_JOB_ID. It's not a random number, but it's unique.
variables: MERGE_ID: $CI_JOB_ID If you're referring to the gitlab-ci.yml file, this is possible. Each GitLab job defined in the YAML file provides a script section where you can define bash commands that will get executed by GitLab when the job is run. If you want more complex operations, you can call Python scripts from the script section.
Fortunately, in this case, bash has a built-in $RANDOM function, described in How to generate random number in Bash?.
gitlab-ci.yml:
my-job: stage: my-stage script: # Generate random number from 1 to 10: - let MR_ID=$((1 + RANDOM % 10)) 3