如何在Jenkins上通过构建步骤触发构建的URL? [英] How to I get the url of build triggered with build step on Jenkins?

查看:1172
本文介绍了如何在Jenkins上通过构建步骤触发构建的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins中使用基于Groovy的管道时,您可以使用构建阶段.

While using Groovy based pipelines in Jenkins you can trigger child jobs using the the build stage.

上面的文档仍然没有说明您将获得哪种返回对象以及其具有的属性.

Still the documentation above states nothing regarding what kind of return object you would get and what attributes it has.

到目前为止,我发现的唯一一件事是,我可以使用build.getResult()来获取触发作业的结果.

The only thing I found so far is that I can use build.getResult() to obtain the result of the triggered job.

不过,我确实想获取此工作的网址.

Still, I do want to obtain the URL of this job.

推荐答案

摘自/pipeline-syntaxbuild步骤的文档(waitFormCompletion参数,原始格式更好):

From the documentation for the build step in /pipeline-syntax (waitFormCompletion argument, the original has better formatting):

您可能会要求此Pipeline构建等待下游构建的完成.在这种情况下,步骤的返回值是一个对象,您可以在该对象上获得以下只读属性:因此,您可以检查其.result等.

You may ask that this Pipeline build wait for completion of the downstream build. In that case the return value of the step is an object on which you can obtain the following read-only properties: so you can inspect its .result and so on.

  • 号码
    内部版本号(整数)
  • 结果
    通常为成功",不稳定"或失败"(对于正在进行的构建,可能为null)
  • currentResult
    通常是成功,不稳定或失败.永远不会为空.
  • resultIsBetterOrEqualTo(String)
    将当前构建结果与提供的结果字符串(SUCCESS,UNSTABLE或FAILURE)进行比较,如果当前构建结果好于或等于提供的结果,则返回true.
  • resultIsWorseOrEqualTo(String)
    将当前构建结果与提供的结果字符串(SUCCESS,UNSTABLE或FAILURE)进行比较,如果当前构建结果差于或等于提供的结果,则返回true.
  • displayName
    通常为#123,但有时设置为例如SCM提交标识符
  • 说明
    有关构建的其他信息
  • id
    通常为数字
  • timeInMillis
    自计划构建的时期以来的时间
  • startTimeInMillis
    自构建开始运行以来的时间
  • 持续时间
    构建持续时间(以毫秒为单位)
  • durationString
    易于理解的构建持续时间
  • previousBuild
    另一个相似的对象,或者为空
  • nextBuild
    类似地
  • absoluteUrl
    构建索引页面的网址
  • buildVariables
    对于非管道下游构建,提供对已定义构建变量的映射的访问;对于管道下游构建,在env上全局设置的所有变量
  • changeSets
    来自不同的SCM检出的变更集列表;每个都有一个,并且是一个提交列表;每个提交都有一个commitId,时间戳,msg,author和受影响的文件,每个文件都有一个editType和路径.该值通常不会被序列化,因此您只能在标有@NonCPS的方法中访问它
  • rawBuild
    使用其他API运行的hudson.model,仅适用于沙箱外部的受信任库或管理员批准的脚本;该值将无法序列化,因此您只能在标有@NonCPS的方法中访问它
  • number
    build number (integer)
  • result
    typically SUCCESS, UNSTABLE, or FAILURE (may be null for an ongoing build)
  • currentResult
    typically SUCCESS, UNSTABLE, or FAILURE. Will never be null.
  • resultIsBetterOrEqualTo(String)
    Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is better than or equal to the provided result.
  • resultIsWorseOrEqualTo(String)
    Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is worse than or equal to the provided result.
  • displayName
    normally #123 but sometimes set to, e.g., an SCM commit identifier
  • description
    additional information about the build
  • id
    normally number as a string
  • timeInMillis
    time since the epoch when the build was scheduled
  • startTimeInMillis
    time since the epoch when the build started running
  • duration
    duration of the build in milliseconds
  • durationString
    a human-readable representation of the build duration
  • previousBuild
    another similar object, or null
  • nextBuild
    similarly
  • absoluteUrl
    URL of build index page
  • buildVariables
    for a non-Pipeline downstream build, offers access to a map of defined build variables; for a Pipeline downstream build, any variables set globally on env
  • changeSets
    a list of changesets coming from distinct SCM checkouts; each has a kind and is a list of commits; each commit has a commitId, timestamp, msg, author, and affectedFiles each of which has an editType and path; the value will not generally be Serializable so you may only access it inside a method marked @NonCPS
  • rawBuild
    a hudson.model.Run with further APIs, only for trusted libraries or administrator-approved scripts outside the sandbox; the value will not be Serializable so you may only access it inside a method marked @NonCPS

如果不等待,只要可以将下游构建添加到队列中,该步骤就会成功(甚至不会启动).在这种情况下,当前没有返回值.

If you do not wait, this step succeeds so long as the downstream build can be added to the queue (it will not even have been started). In that case there is currently no return value.

工作URL不存在(毕竟它是一个构建),但是absoluteUrl为您提供了构建URL.

The job URL doesn't exist (it's a build, after all), but absoluteUrl gives you the build URL.

rawBuild应该可以让您访问例如rawbuild.parent.url(未经测试),但通常不安全,不建议离开沙盒.

rawBuild should let you access e.g. rawbuild.parent.url (untested), but it's generally unsafe and discouraged to leave the sandbox.

这篇关于如何在Jenkins上通过构建步骤触发构建的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆