[英]Get BuildInfo From Artifactory Using Jenkins
Using Jenkins DSL I can create and publish build info using Artifactory.newBuildInfo but am looking for the complementary method to read the BuildInfo JSON data that is generated on Artifactory.使用 Jenkins DSL,我可以使用 Artifactory.newBuildInfo 创建和发布构建信息,但我正在寻找补充方法来读取在 Artifactory 上生成的 BuildInfo JSON 数据。 Have trolled through many resources.已经浏览了许多资源。 Any suggestions would be appreciated.任何建议,将不胜感激。
From Artifactory REST API it sure looks like you can retrieve buildInfo.从Artifactory REST API看来,您确实可以检索 buildInfo。 I'd expect this must be exposed from the jenkins plugin as well.我希望这也必须从 jenkins 插件中公开。
Build Info
Description: Build Info
Since: 2.2.0
Security: Requires a privileged user with deploy permissions (can be anonymous)
Usage: GET /api/build/{buildName}/{buildNumber}
Produces: application/vnd.org.jfrog.build.BuildInfo+json
...
JFrog's project examples on github is a fabulous resource as is their jenkins plugin JFrog 在 github 上的项目示例和他们的jenkins 插件一样是极好的资源
From a quick search it looks like you'd define a download spec and then use server.download method (see Working with Pipeline Jobs in Jenkins通过快速搜索,您似乎定义了一个下载规范,然后使用 server.download 方法(请参阅在 Jenkins 中使用管道作业
def buildInfo1 = server.download downloadSpec
The previous answer creates a new buildInfo, it does not download the original buildInfo into I've been trying for days to try to figure out how to do what the original poster wants to do.上一个答案创建了一个新的 buildInfo,它不会将原始 buildInfo 下载到我已经尝试了几天试图弄清楚如何做原始海报想要做的事情。 The best I've succeeded at is downloading the buildinfo into a hashtable, work with that, then upload the changes doing REST calls.我成功的最好方法是将 buildinfo 下载到哈希表中,使用它,然后通过 REST 调用上传更改。
def curlstr = "curl -H 'X-JFrog-Art-Api:${password}' ${arturl}api/build/${buildName}/${buildNumber}"
def buildInfoString = sh(
script: curlstr,
returnStdout: true
).trim()
buildInfo = (new JsonSlurperClassic().parseText(buildInfoString))
sh("echo '${JsonOutput.toJson(buildInfo)}'|curl -XPUT -H 'X-JFrog-Art-Api:${password}' -H 'Content-Type: application/json' ${arturl}api/build --upload-file - ")
I was able to modify the buildInfo in the artifactory repository using this technique.我能够使用这种技术修改工件存储库中的 buildInfo。 Not as clean as I would like.没有我想要的那么干净。 I've been unable to get the jfrogCLI to modify existing buildInfo files either.我也无法让 jfrogCLI 修改现有的 buildInfo 文件。
For whatever it's worth the intent of what I'm trying to do is promote a docker artifact and change the name while doing it.对于任何值得我尝试做的事情的意图是推广 docker 工件并在执行时更改名称。 There is no way I've found to express this to artifactory not involving downloading the artifact to docker and then pushing it again.我发现没有办法向工件表达这一点,而不涉及将工件下载到 docker 然后再次推送它。 I'd love it if someone from @jfrog could clue me in how to do it.如果来自@jfrog 的人能告诉我如何做,我会很高兴。
UPDATE: Attention!更新:注意! I've got the question wrong.我问错了。 This is how you get the local BuildInfo-Object in a declarative pipeline script.这是您在声明性管道脚本中获取本地 BuildInfo-Object 的方式。
I managed this by using an internal api from jenkins-artifactory-plugin.我通过使用来自 jenkins-artifactory-plugin 的内部 api 来管理这个。
// found in org.jfrog.hudson.pipeline.declarative.utils.DeclarativePipelineUtils
/**
* Get build info as defined in previous rtBuildInfo{...} scope.
*
* @param rootWs - Step's root workspace.
* @param build - Step's build.
* @param customBuildName - Step's custom build name if exist.
* @param customBuildNumber - Step's custom build number if exist.
* @return build info object as defined in previous rtBuildInfo{...} scope or a new build info.
*/
public static BuildInfo getBuildInfo(FilePath rootWs, Run<?, ?> build, String customBuildName, String customBuildNumber, String project) throws IOException, InterruptedException {
...
}
Whith this code you can fetch the BuildInfo inside a declarative pipeline script step.使用此代码,您可以在声明性管道脚本步骤中获取 BuildInfo。
def buildInfo = org.jfrog.hudson.pipeline.declarative.utils.DeclarativePipelineUtils.getBuildInfo(new hudson.FilePath(new java.io.File(env.WORKSPACE)), currentBuild.rawBuild, null, null, null);
UPDATE: Beware of custom build names and numbers.更新:当心自定义构建名称和编号。 I you have defined a custom build name and/or build number, you have to provide it with the getBuildInfo
call.如果您定义了自定义构建名称和/或构建编号,则必须通过getBuildInfo
调用为其提供。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.