0

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.

4
  • Did you try "${var1}..HEAD"? Commented Oct 24, 2024 at 7:22
  • 1
    According to stackoverflow.com/questions/53965695/…, variables should be set with the syntax of VARIABLE=value, not $VARIABLE=value. Try if that works. Commented Oct 24, 2024 at 8:29
  • I've already tried with those options ("${var}...HEAD" returns an error, but "${var}"...HEAD doesn't return anything), but to no use. When I do an "echo" of the variable it returns the value that I assigned, but for some reason it doesn't work on the "git log" command. Commented Oct 25, 2024 at 10:45
  • "var1 = "44368ac18c6a286cfce9a7f2e246b15ff54b405c"" returns an error too, btw, probably because I'm using Powershell and not raw bash. Commented Oct 25, 2024 at 10:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.