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

apply replace on property sonar.branch.name: original value 'null' with '' #542

Closed
wolframhaussig opened this issue Feb 5, 2021 · 4 comments
Milestone

Comments

@wolframhaussig
Copy link

Describe the bug

Hello, I have the same problem as in #457 . I try to get SonarQube to use the git branch name as sonar.branch.name but when running maven I get the following output:

[INFO] --- git-commit-id-plugin:4.0.3:revision (default) @ [REDACTED] ---
...
[INFO] Collected git.branch with value development
...
[INFO] apply replace on property sonar.branch.name: original value 'null' with ''
[INFO] including property git.tags in results
[INFO] including property git.build.version in results
[INFO] including property git.closest.tag.commit.count in results
[INFO] including property git.commit.user.name in results
[INFO] including property git.commit.id.abbrev in results
[INFO] including property git.branch in results
[INFO] including property git.build.host in results
[INFO] including property git.commit.id.describe-short in results
[INFO] including property git.total.commit.count in results
[INFO] including property git.commit.id.describe in results
[INFO] including property git.commit.id in results
[INFO] including property git.build.user.email in results
[INFO] including property git.commit.message.short in results
[INFO] including property git.commit.user.email in results
[INFO] including property git.closest.tag.name in results
[INFO] including property git.local.branch.ahead in results
[INFO] including property sonar.branch.name in results
[INFO] including property git.local.branch.behind in results
[INFO] including property git.commit.time in results
[INFO] including property git.build.time in results
[INFO] including property git.build.user.name in results
[INFO] including property git.dirty in results
[INFO] including property git.commit.message.full in results
[INFO] including property git.remote.origin.url in results

In the end, the property sonar.branch.name is unset. Here is my config:

<plugin>
	<groupId>pl.project13.maven</groupId>
	<artifactId>git-commit-id-plugin</artifactId>
	<executions>
		<execution>
			<goals>
				<goal>revision</goal>
			</goals>
			<phase/>
		</execution>
	</executions>
	<configuration>
		<prefix>git</prefix>
		<verbose>true</verbose>
		<skipPoms>false</skipPoms>
		<dateFormat>dd.MM.yyyy '@' HH:mm:ss z</dateFormat>
		<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
		<useBranchNameFromBuildEnvironment>true</useBranchNameFromBuildEnvironment>
		<gitDescribe>
			<always>true</always>
			<abbrev>7</abbrev>
			<dirty>-dirty</dirty>
			<forceLongFormat>false</forceLongFormat>
		</gitDescribe>
		<replacementProperties>
			<replacementProperty>
				<property>sonar.branch.name</property>
				<token></token>
				<value>${git.branch}</value>
				<regex>false</regex>
			</replacementProperty>
		</replacementProperties>
	</configuration>
</plugin>

Can you give me a hint what I am doing wrong?

Additional context

  • the plugin version is being used:4.0.3
  • the Java-Version is being used: Zulu 11.35
  • the Maven-Version is being used: 3.3.9
  • on what Operating System you experience the bug: Windows 10
  • in what context maven is being executed: Eclipse
  • how maven is being executed: "mvn package" vs. "mvn package sonar:sonar"
@TheSnoozer
Copy link
Collaborator

Hi thank you for creating a ticket for that.

By a quick guess could you perhaps add <injectAllReactorProjects>true</injectAllReactorProjects> to the configuration of the plugin? What I think might go on here is that the plugin is generating the properties, but since you want to use it again inside the pom the property needs to made visible to the pom.

If this doesn't help could you perhaps:

  1. add a static text to the replacement property to see if it ends up in sonar? Like change <value>${git.branch}</value> to <value>this-is-the-banch-${git.branch}-maybe</value>
  2. run the plugin with it's prefix before running sonar (yes a weird bug outlined in Unable to obtain git.branch property with SonarQube build #413 (comment)). Like mvn package pl.project13.maven:git-commit-id-plugin:revision sonar:sonar

If this doesn't help it might get ugly, since maven is not really supportive in terms of running sonar reports and has here some really weird edge cases I can't fix in the plugin.

Hope this helps.

@wolframhaussig
Copy link
Author

Hello @TheSnoozer ,

Thanks a lot for your suggestions! Unfortunately, <injectAllReactorProjects>true</injectAllReactorProjects> did not help but I have kept it in my config just to be sure.

Interestingly, mvn package pl.project13.maven:git-commit-id-plugin:revision sonar:sonar helped: According to the maven console output the git-commit-id-pluginis called twice:

[INFO] --- git-commit-id-plugin:4.0.3:revision (default) @ [redacted] ---
...
[INFO] Collected git.branch with value development
...
[INFO] apply replace on property sonar.branch.name: original value 'null' with ''
[INFO] --- git-commit-id-plugin:4.0.3:revision (default-cli) @ [redacted] ---
...
[INFO] Using cached git.branch with value development
...
[INFO] apply replace on property sonar.branch.name: original value '' with 'development'

I would be fine with this solution but maybe you have an idea how this could work with a single git-commit-id-plugin?

Best regards
Wolfram

@TheSnoozer
Copy link
Collaborator

Hi,
thanks for the feedback and sorry for the slow responses!
IMHO Maven works weird with those plugin prefixes. Sadly this issue is not just limited to the plugin, but since most users want to use a commit or branch name in some downstream application / process the issue becomes obvious once using the plugin (e.g. #287 / https://issues.apache.org/jira/browse/MNG-6260).

So how to make it only run once....that's a good question. When you want to achieve that you essentially want to 'bypass' maven's idea that plugins are independent.
I think this #413 (comment) or this #413 (comment) might allow you to run just mvn package sonar:sonar. You also might get away by skipping the plugin entirely as outlined in #457 (comment).
Another alternative which I believe wasn't discussed in any of the tickets is to make the actual execution of sonar part of the "normal" flow of a build. So instead of running mvn .... sonar:sonar the sonar build could run as part of the install phase...

I know this is all a hack and I must admit the hackish thinking of maven made me abandon it completely :-)
Anyhow i hope this helps to find the right solution for your case...

@wolframhaussig
Copy link
Author

Hi,

Thanks for the clarrification. In this case I will keep the 2 calls.

Thank you for your support!

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

No branches or pull requests

2 participants