Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git.closest.tag values not set in Azure pipeline #633

Open
GJKrupa opened this issue Jun 1, 2023 · 4 comments
Open

git.closest.tag values not set in Azure pipeline #633

GJKrupa opened this issue Jun 1, 2023 · 4 comments
Labels

Comments

@GJKrupa
Copy link

GJKrupa commented Jun 1, 2023

Describe the bug (required)

I have configured a Maven build to include tags and git.closest.tag.* values in git.properties. The verbose log shows that tags are being collected but the git.closest.tag.name and git.closest.tag.commit.count properties are blank. The repository has two tags 0.0.0 and 0.0.1 and the main branch is currently 1 commit ahead of the 0.0.1 tag.

Tell us about your plugin configuration (required)

            <plugin>
                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>6.0.0</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <verbose>true</verbose>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                    <includeOnlyProperties>
                        <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
                        <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
                        <includeOnlyProperty>^git.tags$</includeOnlyProperty>
                        <includeOnlyProperty>^git.closest.tag.*$</includeOnlyProperty>
                        <includeOnlyProperty>^git.dirty$</includeOnlyProperty>
                        <includeOnlyProperty>^git.branch</includeOnlyProperty>
                    </includeOnlyProperties>
                    <commitIdGenerationMode>full</commitIdGenerationMode>
                    <gitDescribe>
                        <tags>true</tags>
                    </gitDescribe>
                </configuration>
            </plugin>

Tell us about the Plugin version used (required)

6.0.0

Tell us about the Maven version used (required)

mvn --version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.7, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-137-generic", arch: "amd64", family: "unix"

Steps to Reproduce (required)

The Azure pipeline looks like the following:

trigger:
  - main

pool:
  name: home-lab

variables:
  - name: storageaccount_name
    value: REDACTED
  - name: container_name
    value: REDACTED

steps:
  - task: Maven@4
    inputs:
      mavenPomFile: 'pom.xml'
      mavenOptions: '-Xmx3072m --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.17'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: true
      testResultsFiles: '**/TEST-*.xml'
      options: '--batch-mode'
      goals: 'package verify'

  - publish: $(System.DefaultWorkingDirectory)/target/openapi.json
    artifact: openapi-spec.json

  - task: AzureCLI@2
    inputs:
      azureSubscription: 'REDACTED'
      scriptType: 'bash'
      scriptLocation: 'inlineScript'
      addSpnToEnvironment: true
      inlineScript: >
        az apim api import
        --path "/"
        --api-id "REDACTED"
        --resource-group "REDACTED"
        --service-name "REDACTED"
        --specification-path "$(System.DefaultWorkingDirectory)/target/openapi.json"
        --specification-format "OpenApiJson" 

  - task: AzureRmWebAppDeployment@4
    inputs:
      ConnectionType: 'AzureRM'
      azureSubscription: 'REDACTED'
      appType: 'webAppLinux'
      WebAppName: 'REDACTED'
      packageForLinux: '$(System.DefaultWorkingDirectory)/target/training-api-app.jar'
      RuntimeStack: 'JAVA|17-java17'
      StartupCommand: >
        java
        -Djava.net.preferIPv4Stack=true
        -Dserver.port=80
        -jar /home/site/wwwroot/training-api-app.jar

Are there any stacktraces or any error messages? (required)

2023-05-31T15:21:04.7695698Z [INFO] dotGitDirectory '/home/krupagj/azure-devops/_work/1/s/.git'
2023-05-31T15:21:05.0473326Z [INFO] Using environment variable based branch name. BUILD_SOURCEBRANCH = refs/heads/main (branch = main)
2023-05-31T15:21:05.0476113Z [INFO] Collected git.branch with value main
2023-05-31T15:21:05.0498662Z [INFO] Collected git.commit.id.full with value 7c96105d762080e184ff6f30ea916df36d50b628
2023-05-31T15:21:05.0511394Z [INFO] Collected git.commit.id.abbrev with value 7c96105
2023-05-31T15:21:05.1047632Z [INFO] Collected git.dirty with value false
2023-05-31T15:21:05.1184023Z [INFO] Collected git.tags with value 
2023-05-31T15:21:05.1204474Z [INFO] evalCommit is [7c96105d762080e184ff6f30ea916df36d50b628]
2023-05-31T15:21:05.1218217Z [INFO] Tag refs [[Ref[refs/tags/0.0.0=e7b8e2074d25e947381d0ea2707ce4152e58fba3(-1)], Ref[refs/tags/0.0.1=1229a63c5f5878f2c1a653c352526d9560f0a725(-1)]]]
2023-05-31T15:21:05.1226996Z [INFO] Including lightweight tag [refs/tags/0.0.0]
2023-05-31T15:21:05.1547469Z [INFO] Including lightweight tag [refs/tags/0.0.1]
2023-05-31T15:21:05.2077783Z [INFO] key [AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]], tags => [[DatedRevTag{id=e7b8e2074d25e947381d0ea2707ce4152e58fba3, tagName='refs/tags/0.0.0', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2086898Z [INFO] key [AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]], tags => [[DatedRevTag{id=1229a63c5f5878f2c1a653c352526d9560f0a725, tagName='refs/tags/0.0.1', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2107915Z [INFO] Created map: [{AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]=[0.0.0], AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]=[0.0.1]}]
2023-05-31T15:21:05.2118550Z [INFO] Collected git.closest.tag.name with value 
2023-05-31T15:21:05.2138544Z [INFO] evalCommit is [7c96105d762080e184ff6f30ea916df36d50b628]
2023-05-31T15:21:05.2149115Z [INFO] Tag refs [[Ref[refs/tags/0.0.0=e7b8e2074d25e947381d0ea2707ce4152e58fba3(-1)], Ref[refs/tags/0.0.1=1229a63c5f5878f2c1a653c352526d9560f0a725(-1)]]]
2023-05-31T15:21:05.2151702Z [INFO] Including lightweight tag [refs/tags/0.0.0]
2023-05-31T15:21:05.2156059Z [INFO] Including lightweight tag [refs/tags/0.0.1]
2023-05-31T15:21:05.2161957Z [INFO] key [AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]], tags => [[DatedRevTag{id=e7b8e2074d25e947381d0ea2707ce4152e58fba3, tagName='refs/tags/0.0.0', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2168558Z [INFO] key [AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]], tags => [[DatedRevTag{id=1229a63c5f5878f2c1a653c352526d9560f0a725, tagName='refs/tags/0.0.1', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2172772Z [INFO] Created map: [{AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]=[0.0.0], AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]=[0.0.1]}]
2023-05-31T15:21:05.2174466Z [INFO] Collected git.closest.tag.commit.count with value 
2023-05-31T15:21:05.2248081Z [INFO] Collected git.build.time with value 2023-05-31T15:21:05+0000
2023-05-31T15:21:05.2249476Z [INFO] Collected git.build.version with value 0.0.1-SNAPSHOT
2023-05-31T15:21:05.2339179Z [INFO] including property 'git.tags' in results
2023-05-31T15:21:05.2340026Z [INFO] including property 'git.closest.tag.commit.count' in results
2023-05-31T15:21:05.2349184Z [INFO] including property 'git.build.version' in results
2023-05-31T15:21:05.2349407Z [INFO] including property 'git.commit.id.full' in results
2023-05-31T15:21:05.2349641Z [INFO] including property 'git.commit.id.abbrev' in results
2023-05-31T15:21:05.2349858Z [INFO] including property 'git.closest.tag.name' in results
2023-05-31T15:21:05.2350058Z [INFO] including property 'git.branch' in results
2023-05-31T15:21:05.2350243Z [INFO] including property 'git.build.time' in results
2023-05-31T15:21:05.2350430Z [INFO] including property 'git.dirty' in results
2023-05-31T15:21:05.2364699Z [INFO] Writing properties file [/home/krupagj/azure-devops/_work/1/s/target/classes/git.properties] (for project demo)...
2023-05-31T15:21:05.2492364Z [INFO] 
2023-05-31T15:21:05.2493353Z [INFO] --- git-commit-id-maven-plugin:6.0.0:revision (get-the-git-infos) @ training-api-app ---
2023-05-31T15:21:05.2512375Z [INFO] dotGitDirectory '/home/krupagj/azure-devops/_work/1/s/.git'
2023-05-31T15:21:05.2531959Z [INFO] Using environment variable based branch name. BUILD_SOURCEBRANCH = refs/heads/main (branch = main)
2023-05-31T15:21:05.2532562Z [INFO] Collected git.branch with value main
2023-05-31T15:21:05.2537173Z [INFO] Collected git.commit.id.full with value 7c96105d762080e184ff6f30ea916df36d50b628
2023-05-31T15:21:05.2537680Z [INFO] Collected git.commit.id.abbrev with value 7c96105
2023-05-31T15:21:05.2604335Z [INFO] Collected git.dirty with value false
2023-05-31T15:21:05.2622825Z [INFO] Collected git.tags with value 
2023-05-31T15:21:05.2635842Z [INFO] evalCommit is [7c96105d762080e184ff6f30ea916df36d50b628]
2023-05-31T15:21:05.2643835Z [INFO] Tag refs [[Ref[refs/tags/0.0.0=e7b8e2074d25e947381d0ea2707ce4152e58fba3(-1)], Ref[refs/tags/0.0.1=1229a63c5f5878f2c1a653c352526d9560f0a725(-1)]]]
2023-05-31T15:21:05.2646826Z [INFO] Including lightweight tag [refs/tags/0.0.0]
2023-05-31T15:21:05.2650754Z [INFO] Including lightweight tag [refs/tags/0.0.1]
2023-05-31T15:21:05.2656801Z [INFO] key [AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]], tags => [[DatedRevTag{id=e7b8e2074d25e947381d0ea2707ce4152e58fba3, tagName='refs/tags/0.0.0', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2663850Z [INFO] key [AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]], tags => [[DatedRevTag{id=1229a63c5f5878f2c1a653c352526d9560f0a725, tagName='refs/tags/0.0.1', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2668124Z [INFO] Created map: [{AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]=[0.0.0], AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]=[0.0.1]}]
2023-05-31T15:21:05.2669862Z [INFO] Collected git.closest.tag.name with value 
2023-05-31T15:21:05.2684987Z [INFO] evalCommit is [7c96105d762080e184ff6f30ea916df36d50b628]
2023-05-31T15:21:05.2693845Z [INFO] Tag refs [[Ref[refs/tags/0.0.0=e7b8e2074d25e947381d0ea2707ce4152e58fba3(-1)], Ref[refs/tags/0.0.1=1229a63c5f5878f2c1a653c352526d9560f0a725(-1)]]]
2023-05-31T15:21:05.2696371Z [INFO] Including lightweight tag [refs/tags/0.0.0]
2023-05-31T15:21:05.2700307Z [INFO] Including lightweight tag [refs/tags/0.0.1]
2023-05-31T15:21:05.2705845Z [INFO] key [AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]], tags => [[DatedRevTag{id=e7b8e2074d25e947381d0ea2707ce4152e58fba3, tagName='refs/tags/0.0.0', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2710835Z [INFO] key [AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]], tags => [[DatedRevTag{id=1229a63c5f5878f2c1a653c352526d9560f0a725, tagName='refs/tags/0.0.1', date=May 31, 23 at 3:21:05 PM UTC}]] 
2023-05-31T15:21:05.2718239Z [INFO] Created map: [{AnyObjectId[e7b8e2074d25e947381d0ea2707ce4152e58fba3]=[0.0.0], AnyObjectId[1229a63c5f5878f2c1a653c352526d9560f0a725]=[0.0.1]}]
2023-05-31T15:21:05.2719021Z [INFO] Collected git.closest.tag.commit.count with value 
2023-05-31T15:21:05.2725961Z [INFO] Collected git.build.time with value 2023-05-31T15:21:05+0000
2023-05-31T15:21:05.2728070Z [INFO] Collected git.build.version with value 0.0.1-SNAPSHOT
2023-05-31T15:21:05.2733056Z [INFO] including property 'git.tags' in results
2023-05-31T15:21:05.2735283Z [INFO] including property 'git.closest.tag.commit.count' in results
2023-05-31T15:21:05.2736941Z [INFO] including property 'git.build.version' in results
2023-05-31T15:21:05.2737490Z [INFO] including property 'git.commit.id.full' in results
2023-05-31T15:21:05.2738491Z [INFO] including property 'git.commit.id.abbrev' in results
2023-05-31T15:21:05.2740243Z [INFO] including property 'git.closest.tag.name' in results
2023-05-31T15:21:05.2741723Z [INFO] including property 'git.branch' in results
2023-05-31T15:21:05.2743339Z [INFO] including property 'git.build.time' in results
2023-05-31T15:21:05.2743769Z [INFO] including property 'git.dirty' in results
2023-05-31T15:21:05.2747119Z [INFO] Reading existing properties file [/home/krupagj/azure-devops/_work/1/s/target/classes/git.properties] (for project demo)...
2023-05-31T15:21:05.2756945Z [INFO] Properties file [/home/krupagj/azure-devops/_work/1/s/target/classes/git.properties] is up-to-date (for module demo)...

Is there a (public) project where this issue can be reproduced? (optional)

No response

Your Environment (optional)

I have provisioned a Linux runner based on Ubuntu 20.04 with Java and Maven installed using apt

Context (optional)

No response

@GJKrupa
Copy link
Author

GJKrupa commented Jun 1, 2023

If I run the same Maven command from my MacBook with the same revision checked out, the values are populated correctly

@TheSnoozer
Copy link
Collaborator

Hi, thanks for creating this issue! Could you perhaps check if the problem is also present when using <useNativeGit>true</useNativeGit>? Thanks!

@GJKrupa
Copy link
Author

GJKrupa commented Jun 7, 2023

Unfortunately that doesn't seem to have made a difference. I used the following config:

            <plugin>
                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>6.0.0</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <verbose>true</verbose>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                    <includeOnlyProperties>
                        <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
                        <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
                        <includeOnlyProperty>^git.tags$</includeOnlyProperty>
                        <includeOnlyProperty>^git.closest.tag.*$</includeOnlyProperty>
                        <includeOnlyProperty>^git.dirty$</includeOnlyProperty>
                        <includeOnlyProperty>^git.branch</includeOnlyProperty>
                    </includeOnlyProperties>
                    <commitIdGenerationMode>full</commitIdGenerationMode>
                    <useNativeGit>true</useNativeGit>
                    <gitDescribe>
                        <tags>true</tags>
                    </gitDescribe>
                </configuration>
            </plugin>

and got the following logs (and corresponding blank properties in git.properties):

[INFO] dotGitDirectory '/home/krupagj/azure-devops/_work/1/s/.git'
[INFO] Using environment variable based branch name. BUILD_SOURCEBRANCH = refs/heads/main (branch = main)
[INFO] Collected git.branch with value main
[INFO] Collected git.commit.id.full with value 78abdff1e802cc57c9e1aca5c8509df0bb3c4dd3
[INFO] Collected git.commit.id.abbrev with value 78abdff
[INFO] Collected git.dirty with value false
[INFO] Collected git.tags with value 
[INFO] Collected git.closest.tag.name with value 
[INFO] Collected git.closest.tag.commit.count with value 
[INFO] Collected git.build.time with value 2023-06-07T08:40:30+0000
[INFO] Collected git.build.version with value 0.0.1-SNAPSHOT
[INFO] including property 'git.tags' in results
[INFO] including property 'git.closest.tag.commit.count' in results
[INFO] including property 'git.build.version' in results
[INFO] including property 'git.commit.id.full' in results
[INFO] including property 'git.commit.id.abbrev' in results
[INFO] including property 'git.closest.tag.name' in results
[INFO] including property 'git.branch' in results
[INFO] including property 'git.build.time' in results
[INFO] including property 'git.dirty' in results

@TheSnoozer
Copy link
Collaborator

Thanks for trying, will need to investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants