Semyon Kolesnikov
Semyon Kolesnikov

Reputation: 13

Gitlab CI Trigger pipeline by API with workflow rules

I'm having the following workflow rules in my main pipeline:

   workflow:
      rules:
        - if: '$CI_MERGE_REQUEST_IID == null'
          when: never
        - if: '$CI_MERGE_REQUEST_TITLE =~ /Draft:/'
          when: never
        - if: '$CI_MERGE_REQUEST_TITLE =~ /WIP:/'
          when: never
        - if: '$CI_PIPELINE_TRIGGERED =~ "true"'
          when: always
        - when: always

The issue is when I'm trying to trigger it with the following curl request it tells me that pipeline is filtered out by workflow rules and I can't figure out what's wrong.

This is the curl request that I'm trying to use:

curl --verbose -X POST -F token=$TRIGGER_TOKEN -F ref=BRANCH_NAME https://gitlab_url/api/v4/projects/357/trigger/pipeline"

Upvotes: 1

Views: 2006

Answers (1)

Tolis Gerodimos
Tolis Gerodimos

Reputation: 4400

The issue seems to be with how Gitlab evaluates the rules. Quoted from https://docs.gitlab.com/ee/ci/jobs/job_control.html#specify-when-jobs-run-with-rules
Rules are evaluated in order until the first match. When a match is found, the job is either included or excluded from the pipeline, depending on the configuration

For example, in your case the first rule evaluated is

- if: '$CI_MERGE_REQUEST_IID == null'
  when: never

If the merge request iid is null, gitlab won't evaluate the other rules. And stop the execution

If the rule doesn't match then it will sequently evaluate the next rules, following the same principle

Upvotes: 1

Related Questions