Reputation: 2973
In gitlab ci pipeline, I know how to set the dependency between stages.
deploy:
stage: deploy
needs: [iac]
...
I also know to set filter,
iac:
stage: iac
only:
changes:
- iac/*
...
But how to set the dependency and filter together. The conditions are:
stage iac
: if any files under folder iac
are changed, need run this stage, if no change, skip
stage deploy
: depends on stage iac
,
But when stage iac
is skipped (no change), the pipeline will be confused.
'deploy' job needs 'iac' job, but 'iac' is not in any previous stage
Upvotes: 0
Views: 382
Reputation: 1781
Your deploy
stage is looking for iac
stage evrytime, you need to apply the same rules to both stages. You can use the rules keywords because :
only and except are not being actively developed. rules is the preferred keyword to control when to add jobs to pipelines.
So you can define a global rule and extends it to the jobs you want to filter :
.rules:iac-changes:
rules:
- changes:
- iac/*
deploy:
stage: deploy
extends:
- .rules:iac-changes
needs: [iac]
...
iac:
stage: iac
extends:
- .rules:iac-changes
...
If you want to run the deploy
stage anyway, you can make the needs optional.
Upvotes: 1