I have a Gitlab pipeline and I want certain jobs to only run if certain files have changes from the previous commit. Here's my code:
.gitlab-ci.yml
include:
- local: .ci/container-images.yml
rules:
- changes:
paths:
- "ansible/**/*"
- "docker/**/*"
compare_to: $CI_DEFAULT_BRANCH
.ci/container-images.yml
"build-docker-$[[ inputs.image ]]":
rules:
- changes:
paths:
- $[[ inputs.context ]]/**/*
compare_to: $CI_COMMIT_BEFORE_SHA
First I get this error for .gitlab-ci.yml
:
include:rules:changes:compare_to is not a valid ref
Then if I set compare_to: main
in .gitlab-ci.yml
, I get this error from .ci/container-images.yml
:
Failed to parse rule for build-docker-ansible-builder: rules:changes:compare_to is not a valid ref
I've tried manually entering a branch name & commit SHA and it works of course.
I'm confused about how these variables work, because according to this:
CI/CD variables are supported.
But then according to this:
Predefined variables made available by the runner cannot be used with trigger jobs or these keywords:
So can I use the variables or not? I would find it very surprising that it's not possible to dynamically specify which ref to compare?
If variables are not allowed, is there another way to accomplish this?
Yes while surprising it does not currently support expansion of variables at the compare_to
key. There's a tracking issue here.
It's been fixed and rolled out already, but judging from the comments seems like it won't come out until version 17.2
gets released