开发者

How to retrieve the version,artifactId,package of the artifact built on Hudson

After building the artifact i am executing a script as a Post Build Action to deploy the artifact. So im trying to read the location where it is built.The environment Variables available in Hudson is not givng me enough information about the artifactId, V开发者_Python百科ersion, PackageType of the artifact.

So can anyone help me out on how to get the values for these....

Thanks in Advance


All artifacts built by Maven contain META-INF entries that hold this information. Read them as JarFile:

JarFile jf = new JarFile(path/to/artifact);
JarEntry propsEntry = jf.getJarEntry("META-INF/maven/pom.properties");
Properties props = new Properties();
props.load(jf.getInputStream(propsEntry));
// retrieve the values:
String groupId = props.get("groupId");
String artifactId = props.get("artifactId");
String version = props.get("version");


I might have misunderstood your question completely, but is there a reason not to pick up the artifact via the filesystem and the WORKSPACE environment variable, ${WORKSPACE}/target/...


You can use http://${BUILD_URL}/job/${JOBNAME}/${BUILDNUMBER}/api/xml?xpath=//artifact/fileName/text() and set that to an environment variable. This only works if you have 1 artifact, if you have more, then you'll need to do some additional parsing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜