Tzvetlin Velev
Tzvetlin Velev

Reputation: 2027

Gitlab CI/CD Trigger only a single stage in gitlab-ci.yml file on a scheduled pipeline

I want to run a single stage in gitlab from a yml file that contains a lot of stages. I don't want to have to add this to every single stage to avoid running all the stages.

except:
    refs:
      - schedules

Upvotes: 5

Views: 4602

Answers (3)

Rstew
Rstew

Reputation: 605

You can use the following to run the stage only on a scheduled job

build-app:
  stage: build-app
  only:
    - schedules

Upvotes: 1

Sergio Tanaka
Sergio Tanaka

Reputation: 1435

If you don't want to add except in each job, use only instead of except

https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-advanced

below there is an example with variables

only_with_variable:
  script: ls -la
  only:
    variables:
      - $VAR == "1234"

after that if you schedule a pipeline, you have the option to add variables to them.

enter image description here

in the example, you just need to add the VAR variable with value = 1234

Upvotes: 1

Partiban
Partiban

Reputation: 166

Instead of explicitly defining the except tag for each job. You can define it once as an anchor.

.job_template: &job_definition
  except:
    refs:
      - schedules

test1:
  <<: *job_definition
  script:
    - test1 project

Upvotes: 1

Related Questions