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

查看:75
本文介绍了如何在 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-syntax (waitFormCompletioncode> 参数,原文格式更好):

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

您可能会要求此流水线构建等待下游构建完成.在这种情况下,步骤的返回值是一个对象,您可以在该对象上获得以下只读属性:因此您可以检查其 .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.

  • 号码
    内部版本号(整数)
  • 结果
    通常为 SUCCESS、UNSTABLE 或 FAILURE(对于正在进行的构建可能为 null)
  • 当前结果
    通常是成功、不稳定或失败.永远不会为空.
  • resultIsBetterOrEqualTo(String)
    将当前构建结果与提供的结果字符串(SUCCESS、UNSTABLE 或 FAILURE)进行比较,如果当前构建结果优于或等于提供的结果,则返回 true.
  • resultIsWorseOrEqualTo(String)
    将当前构建结果与提供的结果字符串(SUCCESS、UNSTABLE 或 FAILURE)进行比较,如果当前构建结果比提供的结果差或等于提供的结果,则返回 true.
  • 显示名称
    通常 #123 但有时设置为例如 SCM 提交标识符
  • 说明
    关于构建的附加信息
  • id
    通常数字作为字符串
  • timeInMillis
    自计划构建的纪元以来的时间
  • startTimeInMillis
    自构建开始运行以来的时间
  • 持续时间
    以毫秒为单位的构建持续时间
  • 持续时间字符串
    构建持续时间的人类可读表示
  • 上一个构建
    另一个类似的对象,或 null
  • 下一个构建
    同样
  • absoluteUrl
    构建索引页面的 URL
  • 构建变量
    对于非流水线下游构建,提供对已定义构建变量映射的访问;对于管道下游构建,在 env 上全局设置的任何变量
  • 变更集
    来自不同 SCM 检出的变更集列表;每个都有一个种类,是一个提交列表;每个提交都有一个 commitId、时间戳、msg、作者和受影响的文件,每个都有一个 editType 和路径;该值通常不是可序列化的,因此您只能在标记为 @NonCPS 的方法中访问它
  • 原始构建
    带有更多 API 的 hudson.model.Run,​​仅适用于沙箱外的受信任库或管理员批准的脚本;该值将不可序列化,因此您只能在标记为 @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天全站免登陆