ha9u63a7
ha9u63a7

Reputation: 6804

gitlab-ci.yml - override a specific job and script execution

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,

Upvotes: 23

Views: 41963

Answers (2)

mahdi
mahdi

Reputation: 932

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

plan-dummy:
  before_script:
    - terraform refresh 

Upvotes: 28

danielnelz
danielnelz

Reputation: 5136

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 

Upvotes: -4

Related Questions