[英]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.
因此,我试图读取其构建位置。Hudson中可用的环境变量无法为我提供有关工件ID,版本,PackageType的足够信息。
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. Maven构建的所有工件都包含保存此信息的META-INF条目。 Read them as JarFile:
将其读取为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. 您可以使用
http://${BUILD_URL}/job/${JOBNAME}/${BUILDNUMBER}/api/xml?xpath=//artifact/fileName/text()
并将其设置为环境变量。 This only works if you have 1 artifact, if you have more, then you'll need to do some additional parsing. 仅当您有1个工件时才有效,如果有更多工件,则需要进行一些额外的解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.