Gitlab: trigger manual action via API

The API call you’re using is to trigger the step, not to start it manually. If you change your job definition to accept triggers or manual actions, then your current API call would work. We can do this with the rules keyword:

test:
  stage: test
  script:
    - echo test
  when: manual
  rules:
    - if: “$CI_PIPELINE_SOURCE == ‘trigger’”
       when: always

What this does is set the default to manual so it can still be started in the UI, but also check the $CI_PIPELINE_SOURCE predefined variable to see if the pipeline was triggered. If so, it will always run.

You can see the docs for the rules keyword here: https://docs.gitlab.com/ee/ci/yaml/#rules and all of the predefined variables here: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top