20

My GitLab pipelines execute automatically on every push, I want to manually run pipeline and not on every push.

Pipeline docs: https://docs.gitlab.com/ee/ci/yaml/#workflowrules

I tried this in .gitlab-ci.yml

workflow:
  rules:
    - when: manual    # Error: workflow:rules:rule when unknown value: manual
Anant_Kumar
  • 764
  • 1
  • 7
  • 23

4 Answers4

23

as mentioned in the documentation, you should specify a condition that tells Gitlab to not run the pipeline specifically on push events like so:

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'
      when: never  # Prevent pipeline run for push event
    - when: always # Run pipeline for all other cases

I hope that this may help you :)

Ouma
  • 598
  • 1
  • 4
  • 15
17

We can define your jobs to be only executed on Gitlab. The web option is used for pipelines created by using Run pipeline button in the GitLab UI, from the project's CI/CD > Pipelines section.

only:
   - web
M07
  • 1,060
  • 1
  • 14
  • 23
15

Here is the solution I cam up with:

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
      when: always
    - when: never

This specifies that it will only run if you click the "Run Pipeline" button in the web UI. In all other cases it will not be triggered.

Drdoomsalot
  • 182
  • 2
  • 8
  • This one works, push does not work – Arun VC Dec 28 '22 at 16:08
  • This does not allow creating a manual pipeline for merge requests. It seems that if you want manual pipelines for merge requests, there's no solution for that using `workflow`. – Blaise Mar 11 '23 at 10:33
-3

the when section should not be within rules

workflow:
  when: manual
Silver
  • 7
  • 2
  • 1
    Inside `workflow:rules` is [exactly where it goes](https://docs.gitlab.com/ee/ci/yaml/index.html#workflowrules), but "when, can only be always or never when used with workflow." – theherk Dec 28 '22 at 14:25
  • you don't have to put it within `rules`, manual jobs exist without it. https://docs.gitlab.com/ee/ci/jobs/job_control.html#create-a-job-that-must-be-run-manually – Silver Dec 29 '22 at 16:29
  • You do when in `workflow`. Notice the top example in your like has it in a "job" called `deploy_prod`, not in `workflow`. – theherk Dec 29 '22 at 20:11