The CI/CD variables are supported for rules:changes and we advice users to migrate to the new syntax because the only and except keywords are deprecated.
Summary
Variable substitution does not work on CI/CD configs
Steps to reproduce
Try to make use of a variable within a only: changes: block
variables:SERVICE_PATH:"services/gitlab-builder-k8s"gitlab-builder-k8s:image:$DOCKER_REGISTRY/gitlab-builder-docker:0.0.5script:-docker build -t $DOCKER_REGISTRY/$SERVICE_NAME:$SERVICE_VERSION -t $DOCKER_REGISTRY/$SERVICE_NAME:latest -f $SERVICE_PATH/Dockerfile $SERVICE_PATHonly:changes:# - services/gitlab-builder-k8s/* works-$SERVICE_PATH/*# does not work
Example Project
We are on prem.
What is the current bug behavior?
The build does not get triggered
What is the expected correct behavior?
The build gets triggered
Relevant logs and/or screenshots
Output of checks
The bug happens on on prem Gitlab with version 11.4.0-ee.0
Results of GitLab environment info
Expand for output related to GitLab environment info
System information
System:
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.4.4p296
Gem Version: 2.7.6
Bundler Version:1.16.2
Rake Version: 12.3.1
Redis Version: 3.2.12
Git Version: 2.18.1
Sidekiq Version:5.2.1
Go Version: unknown
GitLab information
Version: 11.4.0-ee
Revision: cfe266c
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
DB Version: 9.6.8
URL:
HTTP Clone URL:
SSH Clone URL:
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
Expand for output related to the GitLab application check
Checking GitLab Shell ...
GitLab Shell version >= 8.3.3 ? ... OK (8.3.3)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
5/2 ... ok
5/3 ... ok
7/4 ... ok
5/5 ... ok
6/7 ... ok
5/8 ... ok
5/9 ... ok
20/11 ... ok
5/12 ... ok
5/13 ... ok
5/14 ... ok
5/15 ... ok
6/17 ... ok
26/18 ... ok
20/19 ... repository is empty
20/24 ... ok
23/26 ... repository is empty
7/27 ... ok
6/28 ... ok
7/29 ... ok
7/30 ... ok
6/31 ... ok
7/32 ... ok
6/33 ... ok
7/34 ... repository is empty
15/36 ... ok
6/37 ... ok
6/38 ... repository is empty
5/39 ... ok
20/40 ... ok
20/41 ... repository is empty
33/42 ... ok
7/46 ... ok
26/47 ... ok
5/50 ... ok
20/54 ... ok
13/55 ... ok
26/56 ... ok
34/57 ... ok
26/58 ... ok
5/59 ... ok
26/60 ... ok
20/61 ... ok
26/62 ... ok
20/64 ... ok
20/65 ... repository is empty
12/67 ... ok
14/68 ... repository is empty
26/69 ... ok
5/70 ... ok
5/71 ... ok
46/72 ... repository is empty
46/73 ... ok
27/74 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml
Checking LDAP ...
Supported for definitions where the "Expansion place" is:
Runner.
Script execution shell.
Not supported:
For definitions where the "Expansion place" is GitLab.
In the only and except variables expressions.
As i understand it, Variables aren't expanded until the job is actually run, so you can't use variables in only/except, except in the 'variables:' part (but only non-job variables i.e. project variables)
edit: Should be noted that I am not affiliated with Gitlab, just a fellow user who ran into the same problem, wishing it would work and then stumbling on the linked documentation
Pragmatically, you're obviously right, it doesn't work and in not working is "working as designed".
However I don't read the docs as being quite as definitive. The "not supported" section you cite refers to persisted variables. What do the first two entries in this table mean?
@jlenny Does this make sense to include as part of &1237 (closed)? It seems like a good way to make CI powerful using concepts that we already have. Maybe only to build into rules:if, since I think we want to focus on improving that syntax and deprecating only/except.
It's a nontrivial amount of work, because variables interpolation is completely built into the syntax parsing and evaluation of only:variables/rules:if and that would need to be extracted somehow to use in changes, but from a usage standpoint I think it makes sense to do.
Also would love to see this implemented. We use a monorepo, and having to hardcode the folder name for each service causes over a hundred lines in our gitlab-ci.yaml file to be duplicated.
Maybe this can be linked to this epic: &812 (closed)
@jyavorska As Drew mentioned in his comment, would we want to support this feature request regarding variables with rules:if rather than add to only/except?
Yes, I think that's the way we'd want to go @thaoyeager. One thing we should double check is make sure that our documentation for everything under only/except is helping people discover rules:if.
This appears to be a special case of the broader issue gitlab-runner#1809 (closed), which is being investigated for a solution. Please join the discussion there, or please let me know if I've missed something and this actually is a separate issue.
@jyavorska : Can you re-open this item? Obviously it is not a duplicate of gitlab-runner#1809 (closed) as no one in 1809 can explain why it would be a duplicate. Thanks :)
This feature would be really neat with my use case for building and deploying OpenFaaS functions
.deploy-fn:stage:deployonly:changes:-$CI_JOB_NAME/package.json-$CI_JOB_NAME/pom.xmlscript:-./faas-cli up --tag=sha --filter "$CI_JOB_NAME"fn-do-all-the-things:extends:.deploy-fn
-> Every time someone updates the version of a function in the languages corresponding manifest file redeploy only the changed function to OpenFaaS
Can you please take a look at this issue @thaoyeager?
@tnir : #1809 does not solve this issue. But I think it might be a duplicate of #34272 (closed) (using the new "rules" syntax vs the old "only" syntax in this ticket). I also just found #214527 (closed) which might also be a duplicate of #34272 (closed).
Having a large monorepo where all my services (and their path, dockerfile, etc) are referenced by variables, this would be really handy to manage my "only:changes:" conditions
I would also LOVE to simplify my CI file by using a variable to reduce repeated code.
My Use Case includes a folder for each "stack" (aka microservice) in the repo, and I am looking to use a CI file that contains the following:
.test_stack_template: tags: - micro stage: test script: "$STACK/test_service" only: changes: - $STACK/**/*test_Example_Stack: extends: .test_stack_template variables: STACK: ExampleStackNameThe desired result would be for the test_Example_Stack job to run when there are changes inside the folder with the name "ExampleStackName" or any of it's subfolders.
It is so weird we can use variables in cache or script but not in only. Is this targeted to be solved for some version? Or can this be archived with rules instead of only?
I wonder if my specific issue is related to using a variable in a hidden job that is extended by the job that sets the variable. In my usage, it works with the script, but not only:changes.
Have you tried this scenario before? (see my previous comment on this thread for an example)
When you commit a change for a file configs/*.txt, this pipeline is created;
It means that; we don't expand variables for only:changes but we do expand variables for rules:changes. Yet, we don't expand variables for rules:exists. I guess we also need to solve this for rules:exits.
I wonder why we didn't implement variables for only:changes while doing it for rules:changes in #34272 (closed) & ! 45037. @mbobin Do you remember anything related to this?
I wonder why we didn't implement variables for only:changes while doing it for rules:changes
I noticed that our documentation states that only and except are not being actively developed. rules is the preferred keyword to control when to add jobs to pipelines.
@furkanayhan I think each keyword has it own class responsible for the evaluation(from what I remember) and we need to implement one by one. Here is the issue for rules:exists: #283881 (closed)
I'm pretty sure it didn't work when I had ./images/${DIRECTORY}/**/* (leading ./), which would seem strange, but perhaps I had something else misconfigured .
I'm trying to do something similar: I have a repository for all my Docker images and each image has it's own directory.
I've configured a matrix build job listing each image as a list item of a variable as each image should be build the same way and I want to avoid code duplication wherever possible.
That should be quite similar to that example from @jamesmontalvo3. It also works whenever I manually trigger the pipeline (or by schedule). But the pipeline is never triggered by changes in the sub-directory.
So, I guess I'm affected by the issue, that this does not work if the only.changes rule is starting with the variable name as mentioned by @jean-keumar, right? I.e. something like ${IMAGE_NAME}/**/* does not work but images/${IMAGE_NAME}/**/* should work?
Edit: Moving my image folders to a images sub-folder and using images/${IMAGE_NAME}/**/* in the only.changes rule also does not trigger the job whenever anything changes in the sub-folder of the image (i.e. changing the Dockerfile does not trigger the build job).
Edit 2: Got it working by specifying the IMAGE_NAME as in the example from @jamesmontalvo3 (i.e. repeating the variable name for each image):
Now, whenever something in the image sub-folder changes, the job for the image is started as expected. I.e. changing the Dockerfile for image-2 triggers a job for image-2.
I would appreciate if you could share use cases when inputs is not a suitable solution. While we know its limitations, we don't know if they are actually important in this case.
Furkan Ayhanchanged the descriptionCompare with previous version
The CI/CD variables are supported for rules:changes and we advice users to migrate to the new syntax because the only and except keywords are deprecated.