gpt4 book ai didi

groovy - 如何获取 Jenkins 上的构建步骤触发的构建的 url?

转载 作者:行者123 更新时间:2023-12-02 06:40:25 26 4
gpt4 key购买 nike

在 Jenkins 中使用基于 Groovy 的管道时,您可以使用 build stage 触发子作业。 .

上面的文档仍然没有说明您将获得哪种类型的返回对象以及它具有哪些属性。

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

不过,我确实想获取该职位的 URL。

最佳答案

来自 /pipeline-syntaxbuild 步骤的文档(waitFormCompletion 参数,原始版本具有更好的格式):

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.

  • 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。

rawBuild 应该让您访问例如rawbuild.parent.url(未经测试),但通常不安全,不鼓励离开沙箱。

关于groovy - 如何获取 Jenkins 上的构建步骤触发的构建的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46262862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com