I've encountered a problem while using 'git log' in one stage of my GitLab pipeline. For some reason, when I try to filter the logs using the commit SHA, it doesn't work, but ONLY when I introduce the commit SHA using a variable.
The code in my stage is:
update_changelog:
stage: version
script:
- $var1 = "44368ac18c6a286cfce9a7f2e246b15ff54b405c"
- git log --pretty=format:"%s" ${var1}..HEAD
- git log --pretty=format:"%s" 44368ac18c6a286cfce9a7f2e246b15ff54b405c..HEAD
allow_failure: false
And so, the output of this pipeline goes like this:
$ $var1 = "44368ac18c6a286cfce9a7f2e246b15ff54b405c"
$ git log --pretty=format:"%s" ${var1}..HEAD
$ git log --pretty=format:"%s" 44368ac18c6a286cfce9a7f2e246b15ff54b405c..HEAD
Typo comillas
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Test hardcode vs. variable
Actualizar changelog [skip ci]
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Local variable
As you can see, the first 'git log' has no output. The result sould be:
$ $var1 = "44368ac18c6a286cfce9a7f2e246b15ff54b405c"
$ git log --pretty=format:"%s" ${var1}..HEAD
Typo comillas
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Test hardcode vs. variable
Actualizar changelog [skip ci]
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Local variable
$ git log --pretty=format:"%s" 44368ac18c6a286cfce9a7f2e246b15ff54b405c..HEAD
Typo comillas
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Test hardcode vs. variable
Actualizar changelog [skip ci]
Merge branch 'feature/TestPipeline_eeml_20241004' of https://git.gmv.es/pi_ssn_test/pi_ssn_test into feature/TestPipeline_eeml_20241004
Local variable
I've tried enclosing the variable between ", but it doesn't work either. Does anybody know why is it that the command "git log" doesn't work when introducing the commit SHA as a variable?
Note: My runner is using a Powershell executor.
"${var1}..HEAD"?VARIABLE=value, not$VARIABLE=value. Try if that works.