How to use include:local to have a script template?

How to use include:local to have a script template?

I have some jobs that are identical except for some variables. So I would like to extract the identical part into a template file and use include:local.

Here how I did my template file /templates/.dataflow-template.yaml:

image: python:latest
before_script:
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install apache-beam[gcp]==2.23.0 $PYTHON_LIB
script:
  - python -m $DATAFLOW_MODULE --runner DataflowRunner

And in my .gitlab-ci.yml, I include this template like this:

dataflow:
  stage: DataFlow
  variables:
    DATAFLOW_MODULE: tiling
    PYTHON_LIB: Pillow==7.1.2
  include: '/templates/.dataflow-template.yaml'

But, I have this message :

root config contains unknown keys: dataflow

So:

  • is it possible to use template to define script?
  • if yes, could you help me? :slight_smile:

Thank you for your help

I’m stuck on this issue too. The docs indicate that include is a keyword for Jobs, yet it throws this error when trying to use it: “jobs:job-name config contains unknown keys: include”

Is there some way or workaround to get an include-like feature in the context of a job, to inject some yaml into the job? I can come up with something that will work for this specific case, but it will be more messy than I would like, and probably will be worse in more complex cases.