Reputation: 3981
I have a template.yml
stages:
- a
- b
- c
i have an another.yml
in which I want to re-use and limit the number of available stages
include:
- project: 'project'
ref: project
file: 'ci_templates/.template.yml'
I tried to add in another.yml
stages:
- a
- b
but it fails with c job: chosen stage does not exist
How to re-use in another.yml
only a
and b
stages?
Upvotes: 0
Views: 541
Reputation: 1234
you should add variables and some rules in your template.yml like:
# template.yml
stages:
- stage_1
- stage_2
- stage_3
variables:
ENABLE_STAGE_1: "true"
ENABLE_STAGE_2: "true"
ENABLE_STAGE_3: "true"
stage1 job:
stage: stage_1
script:
echo "stage1 job"
rules:
- if: $ENABLE_STAGE_1 != "true"
when: never
- when: always
stage2 job:
stage: stage_2
script:
echo "stage2 job"
rules:
- if: $ENABLE_STAGE_2 != "true"
when: never
- when: always
stage3 job:
stage: stage_3
script:
echo "stage3 job"
rules:
- if: $ENABLE_STAGE_3 != "true"
when: never
- when: always
when you don't run some stage you can override your variables, look like the .gitlab-ci.yml
# .gitlab-ci.yml
include:
local: template.yml
variables:
ENABLE_STAGE_3: "false"
Upvotes: 1
Reputation: 3981
You could disable c
stage like this
c:
stage: c
rules:
- when: never
Upvotes: 0