当我从构建页面单击“重建”时,jenkins将重建并运行新作业-具有新jenkins内部编号的新作业。
如何获得执行重建的作业的内部版本号?
我不是在谈论以前的内部版本号。
对构建10说我,我进入构建5,然后单击重建。我如何 是 从管道内的内部版本号(5)像我可以用env.BUILD_NUMBER?
env.BUILD_NUMBER
我假设您正在使用Groovy Pipeline,并且已经知道全局变量(请参阅全局变量参考)。
currentBuild
rawBuild
rawBuildObject#getCauses()
下面的脚本:
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 Plugin的使用CauseAction方式错误。如果已固定为this,则控制台输出应为:
CauseAction
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.
请记住scriptApproval当您看到这样的错误时:
scriptApproval
Scripts not permitted to use method hudson.model.Run getCauses. Administrators can decide whether to approve or reject this signature.