I am trying to run a security scan as pre stage on my gitlab pipeline, I need to add this ".pre" stage in a template yaml file which is included in .gitlab.yml. I couldnt find any relevant information on the issue that I am facing.
if I write a ".pre" stage on my .gitlab.yml file this stage runs perfectly before all other stages, but if I add this as template and include it in .gitlab.yml file ".pre" stage is ignored.
Is it a bug or am I doing something wrong
This runs fine
stages:
- build
- test
job1:
stage: build
script:
- echo "This job runs in the build stage."
first-job:
stage: .pre
script:
- echo "This job runs in the .pre stage, before all other stages."
job2:
stage: test
script:
- echo "This job runs in the test stage."
This doesn't run the ".pre" stage
include:
- local: "prestage.yml"
stages:
- build
- test
job1:
stage: build
script:
- echo "This job runs in the build stage."
job2:
stage: test
script:
- echo "This job runs in the test stage."
contents of prestage.yml
first-job:
stage: .pre
script:
- echo "This job runs in the .pre stage, before all other stages."
I am trying to run a security scan as pre stage on my gitlab pipeline, I need to add this ".pre" stage in a template yaml file which is included in .gitlab.yml. I couldnt find any relevant information on the issue that I am facing.
if I write a ".pre" stage on my .gitlab.yml file this stage runs perfectly before all other stages, but if I add this as template and include it in .gitlab.yml file ".pre" stage is ignored.
Is it a bug or am I doing something wrong
This runs fine
stages:
- build
- test
job1:
stage: build
script:
- echo "This job runs in the build stage."
first-job:
stage: .pre
script:
- echo "This job runs in the .pre stage, before all other stages."
job2:
stage: test
script:
- echo "This job runs in the test stage."
This doesn't run the ".pre" stage
include:
- local: "prestage.yml"
stages:
- build
- test
job1:
stage: build
script:
- echo "This job runs in the build stage."
job2:
stage: test
script:
- echo "This job runs in the test stage."
contents of prestage.yml
first-job:
stage: .pre
script:
- echo "This job runs in the .pre stage, before all other stages."
Share
Improve this question
asked Apr 2 at 7:40
Anand JoshiAnand Joshi
4548 silver badges24 bronze badges
1
- I tested this on gitlab and it works normally. Must be something you omitted. gitlab/Rulqu/testpre/-/pipelines/1750180133 – Rulqu Commented 2 days ago
1 Answer
Reset to default 1Yo, so the main reason that its not working is because the stages
keyword in your .gitlab.yml
file overwrites the stages
. Since .pre
is a special stage that isn't listed in .gitlab.yml
, it gets ignored when you define stages:
.
Just add - .pre
to stages
.
include:
- local: "prestage.yml"
stages:
- .pre # Add here
- build
- test
job1:
stage: build
script:
- echo "This job runs in the build stage."
job2:
stage: test
script:
- echo "This job runs in the test stage."
Other settings leave as it is was. And it should work