简体   繁体   中英

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, Version, 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");

我可能完全误解了您的问题,但是有没有理由不通过文件系统和WORKSPACE环境变量${WORKSPACE}/target/...来获取工件${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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM