Get Maven artifact properties from Jenkins plugin

2019-07-21 19:39发布

问题:

I have a Jenkins and a Sonar installation, for which I'm writing a Jenkins plugin that acts after any Maven project is built and asks Sonar for that specific project's metrics. For this, I'm trying to get the Maven groupId and artifactId from the Jenkins plugin and parametrize a Sonar web API request with them.

I'm currently using the perform(AbstractBuild build, Launcher launcher, BuildListener listener) extension point, but I can't seem to find the relevant attributes in the build object.

I have found a few questions that could relate to this problem:

  • project version from maven to sonar using hudson
  • maven picking up environment variable set by jenkins
  • Getting Maven Version in Jenkins

But all of these either use Groovy, that I'd rather avoid, and/or use environment variables, that I had no luck with. Specifically, I have added the following code to the pom.xml:

<jenkins.groupId>${env.POM_GROUPID}</jenkins.groupId>

and used this code in the plugin:

info.append("Jenkins groupId: " + System.getProperty("jenkins.groupId") + "\n");

This outputs "Jenkins groupId: null"

I'll be glad for any pointers, even in radically other directions.