GitLab run pipeline only manually and not automatically
Asked Answered
O

4

33

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
Outport answered 27/10, 2020 at 15:3 Comment(0)
B
32

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
Brachiate answered 27/10, 2020 at 15:20 Comment(0)
C
27

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.

Cocytus answered 7/12, 2021 at 22:43 Comment(2)
This one works, push does not workSpirit
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.Clino
E
19

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
Effie answered 22/4, 2021 at 19:38 Comment(0)
P
-4

the when section should not be within rules

workflow:
  when: manual
Paintbox answered 11/11, 2022 at 15:33 Comment(3)
Inside workflow:rules is exactly where it goes, but "when, can only be always or never when used with workflow."Farina
you don't have to put it within rules, manual jobs exist without it. docs.gitlab.com/ee/ci/jobs/…Paintbox
You do when in workflow. Notice the top example in your like has it in a "job" called deploy_prod, not in workflow.Farina

© 2022 - 2024 — McMap. All rights reserved.