25

I have a .gitlab-ci.yml file that says:

include: - project: 'my-proj/my-gitlab-ci' ref: master file: '/pipeline/gitlab-ci.yml' 

Because of some "Inconvenience" I would like to override some specific stage that is defined on the above mentioned gitlab-ci.yml file injected on my top level .gitlab-ci.yml file. The plan stage I am interested in has the following thing:

plan-dummy: stage: plan script: - terraform plan -lock=false -var-file=vars/vars.tfvars 

What I want to do is override the above on the main .gitlab-ci.yml file such that only the script is executed as an override:

plan-dummy: stage: plan script: - terraform refresh # This is the line I want to add as an additional step before next - terraform plan -lock=false -var-file=vars/dev.tfvars 

How do I achieve that without fiddling with the injected file? Yes, I know that alternative is to do dirty copy-paste from child file, but I don't want to do that.

Regards,

2 Answers 2

32

simply reuse the same job name and add the configuration you need:

plan-dummy: before_script: - terraform refresh 
Sign up to request clarification or add additional context in comments.

2 Comments

if the original "plan-dummy" job has a"before_script" already, will listing a new command "override" it and erase the original command list?
Unfortunately yes. All overrides, overrides definitions in original
-4

You can do the terraform refresh in a before_script part which will be executed before you script:

plan-dummy: extends: plan-dummy before_script: - terraform refresh 

2 Comments

Not working: Found errors in your .gitlab-ci.yml: plan-dummy: circular dependency detected in extends
You don't need to specify extends:, simply reuse the same job name and add the configuration you need.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.