Skip to content

bad variable evaluation while including .gitlab-ci.yml from other repository ( include template )

Summary

Imagine two yaml files, one is a template used by the other one:

project-template:

# .gitlab-ci.yml
variables:
    test: value

stages:
    - test

print:
    stage: test
    variables:
        local: release-$test-%s

    script:
        - echo $test
        - echo $local

project-using:

# .gitlab-ci.yml
variables:
  test: ${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA}

include:
 - project: "project-template"
   ref: master
   file: ".gitlab-ci.yml"

stages:
  - test

Now if you execute pipeline on project-using:

$ echo $test
master-d4e9ded317368b38851076a27950c1fdeee9e8e8
$ echo $local
release-${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA}-%s

Steps to reproduce

  1. Create template pipeline on project 1.
  2. Execute pipeline on project2 including pipeline from project1.

Example Project

Here is the pipeline from the above example

What is the current bug behavior?

Local job variable is not evaluated correctly:

release-${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA}-%s

What is the expected correct behavior?

Local job variable is evaluated correctly:

master-d4e9ded317368b38851076a27950c1fdeee9e8e8

Relevant logs and/or screenshots

[0KRunning with gitlab-runner 13.9.0-rc2 (69c049fd)
[0;m[0K  on docker-auto-scale fa6cab46
[0;m[0K  feature flags: FF_GITLAB_REGISTRY_HELPER_IMAGE:true
[0;msection_start:1615850434:resolve_secrets
[0K[0K[36;1mResolving secrets[0;m
[0;msection_end:1615850434:resolve_secrets
[0Ksection_start:1615850434:prepare_executor
[0K[0K[36;1mPreparing the "docker+machine" executor[0;m
[0;m[0KUsing Docker executor with image ruby:2.5 ...
[0;m[0KPulling docker image ruby:2.5 ...
[0;m[0KUsing docker image sha256:b8f85f05a4c615b08acb073a366ccf8559bdde860861712bb178fb4ee01102a3 for ruby:2.5 with digest ruby@sha256:edc40b439ce1e771849bb398f70b4e202c18d30a0db391f437820bd712774c75 ...
[0;msection_end:1615850470:prepare_executor
[0Ksection_start:1615850470:prepare_script
[0K[0K[36;1mPreparing environment[0;m
[0;mRunning on runner-fa6cab46-project-25167996-concurrent-0 via runner-fa6cab46-srm-1615850388-b29c977b...
section_end:1615850473:prepare_script
[0Ksection_start:1615850473:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m
[0;m[32;1m$ eval "$CI_PRE_CLONE_SCRIPT"[0;m
[32;1mFetching changes with git depth set to 50...[0;m
Initialized empty Git repository in /builds/gitlab-bugs/1-gitlabrunner-passing-variables-include-template-include/.git/
[32;1mCreated fresh repository.[0;m
[32;1mChecking out d4e9ded3 as master...[0;m

[32;1mSkipping Git submodules setup[0;m
section_end:1615850474:get_sources
[0Ksection_start:1615850474:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m
[0;m[0KUsing docker image sha256:b8f85f05a4c615b08acb073a366ccf8559bdde860861712bb178fb4ee01102a3 for ruby:2.5 with digest ruby@sha256:edc40b439ce1e771849bb398f70b4e202c18d30a0db391f437820bd712774c75 ...
[0;m[32;1m$ echo $test[0;m
master-d4e9ded317368b38851076a27950c1fdeee9e8e8
[32;1m$ echo $local[0;m
release-${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA}-%s
section_end:1615850475:step_script
[0Ksection_start:1615850475:cleanup_file_variables
[0K[0K[36;1mCleaning up file based variables[0;m
[0;msection_end:1615850476:cleanup_file_variables
[0K[32;1mJob succeeded
[0;m