gitlabgitlab-cigitlab-pipelines

Is it possible to override the pipeline default image in a hidden job used as a template


I’ve created a hidden job that requires a specific image:

myhiddenjob.yml

.dosomething:
  inherit:
    default: false
  image: curlimages/curl
  script: …

This job is used in a pipeline that has a different base image:

default:
  image: maven:3.8.6-jdk-11

include:
 - remote: 'https://myhiddenjob.yml’

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS compile

testjob:
  stage: mystage
  script:
    - echo "Working…"
    - !reference [.dosomething, script]

The default image provides the mvn command used in the build job. However I want that the testjob uses a different image, the one defined inside the hidden job (curlimages/curl). However, although I specified inherit false, my hidden job uses the default image (maven:3.8.6-jdk-11) instead of the specified (curlimages/curl).

How can I override it in the hidden job definition?


Solution

  • One way is to use extends

    .dosomething:
      image: curlimages/curl
      script: …
    
    testjob:
      stage: mystage
      before_script:
         - .....testjob sepcific commands
      extends: .dosomething
    

    You can also use before_script to add testjob specific commands.