Skip to content

Unable to obtaing git.branch propertyΒ #287

Closed

Description

@NicolaSpreafico

Hi,
I discovered your plugin from here: https://stackoverflow.com/a/13975553
My goal is very simple, having the git branch name inside the build version.

Here is I come so far

<plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <version>2.2.2</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And then the property
<deploy.version>test-${git.branch}</deploy.version>

But the variable is not resolved
[DEBUG] (f) version = test-${git.branch}

Am I missing a basic configuration?

I tried to launch the
pl.project13.maven:git-commit-id-plugin:revision
goal manually and there is no error

Because my filesystem is like this

.../.git
.../project/pom.xml

I also added this configuration, but no changes

<configuration>
    <dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
</configuration>

I also tried to generate the external properties files in order to see if the data is properly gathered from my repo, but no file is created

<!-- this is false by default, forces the plugin to generate the git.properties file -->
<generateGitPropertiesFile>true</generateGitPropertiesFile>

<!-- The path for the properties file to be generated. See Super Pom for default variable reference https://maven.apache.org/guides/introduction/introduction-to-the-pom.html -->
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>

Tha main problem here is that I'm not seeing any error, so I'm going a little blind understanding the problem.

Thanks

Activity

  1. TheSnoozer commented on Jun 30, 2017

    @TheSnoozer
    Collaborator

    By default the plugin doesn't expose the properties into the maven cycle.
    However if you set <injectAllReactorProjects>true</injectAllReactorProjects> you should be able to use the properties within your maven-file and for the outlined scenario.

  2. NicolaSpreafico commented on Jul 7, 2017

    @NicolaSpreafico
    Author

    Here is my current configuration

    <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
        <version>2.2.2</version>
        <configuration>
            <dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
            <injectAllReactorProjects>true</injectAllReactorProjects>
        </configuration>
        <executions>
            <execution>
                <id>get-the-git-infos</id>
                <goals>
                    <goal>revision</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    with this property

    <app.version>${git.branch}-${maven.build.timestamp}</app.version>
    

    but I'm still having the variable unresolved

    Bad value [${git.branch}-2017-07-07]: May only contain lowercase letters, digits, and hyphens.
    
  3. TheSnoozer commented on Jul 8, 2017

    @TheSnoozer
    Collaborator

    Mhh that is somewhat strange.
    I tested this with the following:

    <profile>
    		<id>demo</id>
    		<build>
    			<finalName>${git.branch}-${maven.build.timestamp}</finalName>
    			<plugins>
    				<plugin>
    					<groupId>pl.project13.maven</groupId>
    					<artifactId>git-commit-id-plugin</artifactId>
    					<version>2.2.2</version>
    					<configuration>
    						<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
    						<injectAllReactorProjects>true</injectAllReactorProjects>
    					</configuration>
    					<executions>
    						<execution>
    							<id>get-the-git-infos</id>
    							<goals>
    								<goal>revision</goal>
    							</goals>
    						</execution>
    					</executions>
    				</plugin>
    			</plugins>
    		</build>
    	</profile>
    

    mvn clean package -Pdemo will result in a jar called target/master-2017-07-08T14:05:54Z.jar

    can you do the following:

    1. verify that the git-directory is located in ${project.basedir}/../.git
    2. Set <verbose>true</verbose> inside the git-commit-id-plugin config section
    3. Set <failOnNoGitDirectory>true</failOnNoGitDirectory> inside the git-commit-id-plugin config section
    4. Set <failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo> inside the git-commit-id-plugin config section
    5. since it seems that you may have a parent / child project relation ship; where do you execute your build (inside the parent or child)?
    6. What is the output of git branch -a inside ${project.basedir}/../-Directory?
  4. NicolaSpreafico commented on Jul 10, 2017

    @NicolaSpreafico
    Author

    Hello,

    1. I can confirm you the directory structure
    ../.git
    ../project/pom.xml
    
    1. I do not have a parent/child project, the project folder exists only because the repository holds additional files which are not related to Maven itself (like internal logs, schemes, ...)

    2. Here the output
      image

    After added the flag you asked, here is part of the generated output

    [INFO] --- git-commit-id-plugin:2.2.2:revision (get-the-git-infos) @ my-project ---
    [INFO] dotGitDirectory D:\Documenti\Java\workspace.noovle\my-project-folder\project\..\.git
    [INFO] git.build.user.name Nicola Spreafico
    [INFO] git.build.user.email nicola.spreafico@xxxxxx
    [INFO] git.branch develop
    [INFO] --always = true
    [INFO] --dirty = -dirty
    [INFO] --abbrev = 7
    .....
    

    The develop branch is recognized, but I'm having the same problem on the generated property

    [INFO] GCLOUD: Temporary staging for module default directory left in D:\Documenti\Java\workspace.noovle\my-project-folder\project\target\appengine-staging
    lug 10, 2017 8:14:31 AM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
    INFORMAZIONI: submitting command: C:\Users\Nicola\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd app deploy D:\Documenti\Java\workspace.noovle\my-project-folder\project\target\appengine-staging\app.yaml --no-promote --version ${git.branch}-2017-07-10T06:13:15Z --project xxxxx
    [INFO] GCLOUD: ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [${git.branch}-2017-07-10T06:13:15Z]: May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.
    ```f
    
  5. TheSnoozer commented on Jul 10, 2017

    @TheSnoozer
    Collaborator

    Based on the feedback it seems that the plugin itself can retrieve the information....

    How do you invoke the GCLOUD (that currently has the error with the bad value)?
    Or in other words:

    • Is this a maven plugin that is getting the parameters through the pom?
    • Is the a maven plugin that is getting the parameters through a file?

    If it is a file i would double check if the file is getting filtered.
    If it through the pom I would double check if the properties gets exposed inside the pom.

    Use something like this for debugging purposes:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <phase>package</phase>
                <configuration>
                    <target>
                        <echo>Extracted git-Branch: ${git.branch}</echo>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
  6. NicolaSpreafico commented on Jul 10, 2017

    @NicolaSpreafico
    Author

    Gcloud is a Maven Plugin which is launched with goal deploy
    This is the configuration

    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.maven.plugin.version}</version>
        <configuration>
            <deploy.version>${app.version}</deploy.version>
            <deploy.project>${app.id}</deploy.project>
            <deploy.promote>False</deploy.promote>
        </configuration>
    </plugin>
    

    The <deploy.version>${app.version}</deploy.version> configuration is the one that received the build version, which is a property declared (as reported before) as <app.version>${git.branch}-${maven.build.timestamp}</app.version>

    So I can say that the it gets the values from the pom itself. It seems like the property is not well handled

    So I tried to use directly the property values inside the configuration

    <deploy.version>${git.branch}-${maven.build.timestamp}</deploy.version>
    

    But i'm getting the same error
    GCLOUD: ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [${git.branch}-2017-07-10]: May only contain lowercase letters, digits, and hyphens

  7. TheSnoozer commented on Jul 10, 2017

    @TheSnoozer
    Collaborator

    can you provide an example project where i can reproduce this?

    What is the output of

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <phase>package</phase>
                <configuration>
                    <target>
                        <echo>Extracted git-Branch: ${git.branch}</echo>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
  8. NicolaSpreafico commented on Jul 11, 2017

    @NicolaSpreafico
    Author

    I'm attaching you a sample project with all the plugins configured
    testgit.zip

    In order to use this, I created a simple git repository (only local) and set the HEAD to master (with only 1 commit).

    To invoke the gcloud goal you can use "mvn appengine:deploy". The Maven goal will call GCloud SDK, so you need to have it installed in order to reach the point where the error occurs

    If everything is configured correctly, you should see this Maven log

    lug 11, 2017 8:34:42 AM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
    INFORMAZIONI: submitting command: C:\Users\Nicola\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd app deploy --no-promote --version ${git.branch}-2017-07-11 --project my-app-id
    [INFO] GCLOUD: ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [${git.branch}-2017-07-11]: May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.
    

    The output of the antrun-plugin is

    main:
         [echo] Extracted git-Branch: master
    
  9. TheSnoozer commented on Jul 13, 2017

    @TheSnoozer
    Collaborator

    Well this is somewhat really strange....Currently I can reproduce the problem but don't understand what it is caused by....

    I thought it might be a Maven internal Problem where the @Parameter-Annotation is broken again and created a sample Maven-Project that uses the same stuff as the app-engine (https://github.com/GoogleCloudPlatform/app-maven-plugin/blob/master/pom.xml)

    Just for future reference can be executed by:
    mvn clean install && mvn clean package -Pdemo

    Download project here:
    SampleMavenProject.zip

    I'll update once I have something more concrete....

  10. TheSnoozer commented on Jul 13, 2017

    @TheSnoozer
    Collaborator

    Ok just as a follow up....I cloned the app-maven-plugin from git and introduced some debugging code to verify what is going on....

    The Mojo-Class that is being used for mvn appengine:deploy and taking the version argument can be found here:
    https://github.com/GoogleCloudPlatform/app-maven-plugin/blob/master/src/main/java/com/google/cloud/tools/maven/DeployMojo.java

    In https://github.com/GoogleCloudPlatform/app-maven-plugin/blob/master/src/main/java/com/google/cloud/tools/maven/DeployMojo.java#L142 we have the getter-method that retrieves the parameter:

    @Parameter(alias = "deploy.version", property = "app.deploy.version")
    protected String version;
    

    So far this is pretty much default stuff.

    Now the interesting observation....when using the suggested command it doesn't seem to replace the Maven-project properties no matter what.

    However when changing the plugin-Definition inside the pom.xml to the following:

    <plugin>
      <groupId>com.google.cloud.tools</groupId>
      <artifactId>appengine-maven-plugin</artifactId>
      <version>1.3.1</version>
      <configuration>
        <project>${app.id}</project>
        <deploy.version>${sample.generated}-${maven.version}-${app.version}</deploy.version>
        <deploy.promote>False</deploy.promote>
      </configuration>
      <executions>
        <execution>
          <id>deploy</id>
          <phase>install</phase>
          <goals>
            <goal>deploy</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    and executing mvn clean install the values and properties are getting replaced accordingly.

    TL;DR,

    When calling the Maven-Plugin via the Plugin's Prefix and goal mvn somePrefix:goal it doesn't resolve the variables correctly. When executing the plugin via the normal maven build cycle it is working as expected.

    I'll report this to Maven and link as soon as I can remeber my password.
    There is nothing i can do to fix this besides changing the way the plugin is being called.

  11. TheSnoozer commented on Jul 13, 2017

    @TheSnoozer
    Collaborator

    Maven Sample project to reproduce the issue:
    SampleProjectV2.zip

    mvn clean install && mvn clean package -> working
    mvn clean install && mvn com.test.plugins:testPlugin:deployMojo -> broken
    mvn clean install && mvn com.test.plugins:testPlugin:buildInjectPropertyMojo antrun:run com.test.plugins:testPlugin:deployMojo -> working

    Maven Bug Report:
    https://issues.apache.org/jira/browse/MNG-6260

  12. 20 remaining items

  13. NicolaSpreafico commented on Apr 26, 2019

    @NicolaSpreafico
    Author

    Thank you,
    so, just to be sure, at the moment there is no workaround for having the git.branch name inside SonarQube version?

  14. TheSnoozer commented on Apr 30, 2019

    @TheSnoozer
    Collaborator

    Please refer to #413 (comment) for the difference between the SonarQube issue and this one.

    Since there is not much I can do to fix this (as per comment in the maven issue) I only can refer to the available workaround or suggest to open a ticket with the appengine plugin to have some sort of functionality that makes such behaviour possible.

    Sadly from the perspective of the plugin I nothing left besides closing this as Can't fix :-(

  15. added this to the 3.0 milestone on Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions