简体   繁体   English

如何检索基于Hudson构建的工件的版本,artifactId,软件包

[英]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.

相关问题 如何从maven存储库中找到最新版本的工件 - How do I find the latest version of an artifact from a maven repository 怎么output最新版pip package? - How to output the latest version of a pip package? Jenkins中的Shell脚本无法通过Promotion Build插件获取有关POM_VERSION / POM_ARTIFACTID的信息 - Shell script in Jenkins doesn't get info about POM_VERSION/POM_ARTIFACTID with Promotion Build plugin 如何通过“执行外壳”触发哈德森工作? - How to trigger hudson job through “execute shell”? 如何访问 Hudson 的“控制台输出”? - how to get access to Hudson's “console output”? 在AIX中检索bash版本 - Retrieve bash version in AIX 如何在多模块项目中(使用Shell脚本)从所有pom.xml文件中提取artifactId? - How to extract the artifactId from all pom.xml files using in a multimodule project (using shell script)? Linux-如何比较已安装的软件包版本(通过shell脚本进行新安装) - Linux - How to compare installed package version new install by shell script 如何提前知道apt-get要安装的一些package的版本? - How to know the version of some package to be installed by apt-get in advance? 由于shell脚本文件中的工件版本中没有此类目录或文件而出现错误 - Getting error as no such directory or file in Artifact Version in shell script file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM