Hello, can I count on your help?
I’m having problems trying to use rules with manual condition. I noticed that the variables that I try to use in the “if rules” are returning empty. I verified this by running the “env” command in the script: from the pipeline:
Only a few return results, but they’re not the results I’d like:
$ echo $CI_MERGE_REQUEST_TITLE
$ echo $CI_COMMIT_DESCRIPTION
$CI_COMMIT_DESCRIPTION
$ echo $CI_COMMIT_MESSAGE
Update .gitlab-ci.yml
$ echo $CI_COMMIT_TITLE
Update .gitlab-ci.yml
$ echo $CI_PROJECT_TITLE
Repo Helm Charts
$ echo $TRIGGER_PAYLOAD
$ echo $CI_MERGE_REQUEST_APPROVED
$ echo $CI_MERGE_REQUEST_LABELS
$ echo $CI_MERGE_REQUEST_EVENT_TYPE
I believe it has something to do with me opening the Merge Request via curl inside the JOB.
Contextualizing my pipeline:
- It is a pipeline to serve as a central repository of charts that are developed by other devs. In this repository, the charts are organized in folders according to the name of each team.
I’m using multi-project pipelines.
There are basically two jobs.
1 - Clone the dev repository and send the chart to the central chart repository that is in a different project from the dev.
2 - Push the chart to a chartmuseum.
No Job 1 - I’m consuming the merge request API, and I’m trying to enable a condition so that the job runs according to the labels informed in the open merge request. However, without success. Apparently the variables I try to use are not being satisfied with the values referred to in the merge request data header.
Below is the command used to open the Merge Request:
push-repository-projects:
stage: catalog
before_script:
- TMPDIR=$(mktemp -d)
script:
- cd $TMPDIR
clona repositorio de chart desenvolvido por outro dev
- git clone https://"$USR_TOKEN":"$PWD_TOKEN"@gitlab.com/$PROJECT_PATH
…
- git add .
commit to another project - central chart repository
- git commit -m "Pipeline Merge Request - $PROJECT_NAME "
- git push https://"$USR_TOKEN":"$PWD_TOKEN"@gitlab.com/$CI_PROJECT_PATH
#open merge request
curl --request POST https://gitlab.com/api/v4/projects/${PROJECT_ID}/merge_requests --header "PRIVATE-TOKEN: ${PWD_TOKEN}" \ --header 'Content-Type: application/json' \ --data "{ \"id\": \"${PROJECT_ID}\", \"title\": \"${PROJECT_NAME}\", \"source_branch\": \"${PROJECT_NAME}\", \"labels\": [ \"public\",\"verified\" ], \"remove_source_branch\": true, \"target_branch\": \"main\" }"
In my rules, I’m trying to say that if my merge has a label with the word “public” it depends on a manual action.
rules:
- if: ‘$CI_PIPELINE_SOURCE == “push” || $CI_PIPELINE_SOURCE == “merge_request_event”’
when: never
- if: ‘$CI_MERGE_REQUEST_LABELS =~ “public”’
when: manual
- when: always