Is it possible to automatically detect the top-level directory that contains file that have changes in the commit, and add this to a variable that i can use in another stage ?
Let's say i have a project with :
- folder1/file[1-3].txt
- folder2/folder3/file4.txt
If the commit modify file1.txt, i would like to define a variable that is equal to "folder1".
variables:
- $MYVAR == "folder1"
If the commit modify file4.txt, i would like to define a variable that is equal to "folder2".
variables:
- $MYVAR == "folder2"
Modification to multiple file in different folder should not happen.
And then use that variable in another stage of the pipeline :
MEP:
stage: deploy
script:
- echo $MYVAR
Would that be possible ? Thanks !
CodePudding user response:
You can conditionally define variables with rules:variables:
-- rules can use rules:changes:
to determine if particular files changed.
myjob:
variables:
MY_VAR: "default value"
rules:
- changes:
- folder1/file[1-3].txt
variables:
MY_VAR: folder1 # override MY_VAR when this rule matches
- changes:
- folder2/folder3/file4.txt
variables:
MY_VAR: folder2
Keep in mind only 1 rule matches for any given job/pipeline.