如何从执行重建的地方获取内部版本号? [英] How do I get the build number from where I executed a rebuild?

查看:153
本文介绍了如何从执行重建的地方获取内部版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从构建页面单击重建"时,jenkins将重建并运行新作业-具有新jenkins内部编号的新作业.

When I click "rebuild" from the page of a build jenkins rebuilds and runs a new job- a new job with a new jenkins build number.

如何获取执行重建的作业的内部版本号?

How do I get the build number of the job where I executed the rebuild?

我不是在谈论以前的内部版本号.

Im not talking about the previous build number.

在版本10上说即时消息.我转到版本5,然后单击重建".我如何像在env.BUILD_NUMBER中一样从管道内部那个构建编号(5)?

Say Im on build 10. I go to build 5 and click rebuild. How do I that build number (5) from inside the pipeline like I can with env.BUILD_NUMBER?

推荐答案

我假设您正在使用Groovy Pipeline,并且已经知道全局变量(请参阅全局变量参考).

I assume that you are using Groovy Pipeline and already know the Global Variable (see Global Variable Reference).

  1. currentBuild变量具有字段rawBuild,该字段返回 hudson .model.Run 对象
  2. 调用rawBuildObject#getCauses()rawBuildObject#getCauses()并返回一些Cause对象.
  1. The currentBuild variable has a field rawBuild that return a hudson.model.Run object
  2. Call rawBuildObject#getCauses() or rawBuildObject#getCauses() and return some Cause object.

以下脚本:

node {
    stage('test advance script') {
            echo "current build number: ${currentBuild.number}"
            echo "previous build number: ${currentBuild.previousBuild.getNumber()}"
            def causes = currentBuild.rawBuild.getCauses()
            echo "causes: ${causes}"
            def rebuildCause0 = currentBuild.rawBuild.getCause(com.sonyericsson.rebuild.RebuildCause)
            echo "rebuildCause0: ${rebuildCause0}"
            echo "rebuild up number: ${rebuildCause0.getUpstreamBuild()}"
        }
}

但是正如我们在聊天中讨论的那样,Rebuilder插件错误地使用了CauseAction.如果将其固定为,则控制台输出应为:

But as we discuss in chat, the Rebuilder Plugin use CauseAction in a wrong way. If it is fixed as this, console output should be:

current build number: 72
previous build number: 71
causes: [hudson.model.Cause$UserIdCause@679c1066, job/DMP/job/test-pipeline/63[hudson.model.Cause$UserIdCause@679c1066]]
rebuildCause0: job/DMP/job/test-pipeline/63[hudson.model.Cause$UserIdCause@679c1066]
rebuild up number: 63

当您看到这样的错误时,请记住scriptApproval:

Scripts not permitted to use method hudson.model.Run getCauses. Administrators can decide whether to approve or reject this signature.

Scripts not permitted to use method hudson.model.Run getCauses. Administrators can decide whether to approve or reject this signature.

这篇关于如何从执行重建的地方获取内部版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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