Search code examples
gitlabgitlab-cigitlab-api

Can I push a commit using the gitlab API using push options


I would like to create a commit using the GitLab API:

https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions

skipping CI pipelines (git push -o ci.skip)

https://docs.gitlab.com/ee/user/project/push_options.html#push-options-for-gitlab-cicd

Is that possible?


Solution

  • You can't include push options when creating commits through the API. However, you can the commit message to skip the pipeline in the same way as -o ci.skip.

    By default, if the commit message contains [ci skip], the pipeline will be skipped.

    Alternatively, you can use workflow:rules: to exclude a pipeline on a commit message pattern of your choosing that you control in the commit_message parameter. Alternatively still, you may also do so on any other condition, like perhaps the commit author ($CI_COMMIT_AUTHOR), which you can control in the author_email parameter to the commit API.

    workflow:
      rules:
        - if: '$CI_COMMIT_MESSAGE =~ /mymessage/'
          when: never
        - if: '$CI_COMMIT_AUTHOR == "[email protected]"'
          when: never
        - when: always