简体   繁体   English

使用 Jenkins 从 Artifactory 获取 BuildInfo

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

相关问题 如何从jenkins管道中的Artifactory buildInfo获取构建依赖项 - how to get build dependencies from Artifactory buildInfo in jenkins pipeline JFrog Artifactory的Jenkins管道无法发布BuildInfo - Jenkins pipeline for JFrog Artifactory fails to publish BuildInfo 从 Jenkins 中的工件 URL 获取构建 ID - Get build ID from artifactory URL in Jenkins 带有ConanClient的Jenkins Artifactory插件:巨大的BuildInfo引用了ConanClient返回的无关包 - Jenkins Artifactory Plugin with ConanClient: huge BuildInfo refering unrelated packages returned by ConanClient 使用詹金斯发布到Artifactory - Publishing to Artifactory using Jenkins Mockito 不能模拟这个类(artifactory BuildInfo) - Mockito cannot mock this class (artifactory BuildInfo) 使用 Jenkins 作业将 Artifactory 包从一个文件夹复制到另一个文件夹 - Artifactory Package copy from One Folder to another using Jenkins Job 使用针对.net项目的Jenkins Artifactory插件解析Artifactory Pro中的nuget软件包 - Resolve nuget packages from Artifactory Pro using Jenkins Artifactory plugin for .net projects 使用Jenkins管道推送到Artifactory - Pushing to Artifactory using Jenkins pipeline 使用 Jenkins 的人工制品部署失败 - Artifactory depoyment using Jenkins failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM