如何操作Jenkins管道作业的生成结果(返回到';成功';)?

如何操作Jenkins管道作业的生成结果(返回到';成功';)?,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我在操纵Jenkins管道的构建结果时遇到了一些麻烦。我已经把范围缩小到以下问题:有人知道为什么下面的Jenkins管道不能使构建结果成功吗?相反,构建失败了 print "Setting result to FAILURE" currentBuild.result = 'FAILURE' print "Setting result to SUCCESS" currentBuild.result = 'SUCCESS' 我猜这是故意的,“结果只会变得更糟”在: //结果只会变得更糟 if(r

我在操纵Jenkins管道的构建结果时遇到了一些麻烦。我已经把范围缩小到以下问题:有人知道为什么下面的Jenkins管道不能使构建结果成功吗?相反,构建失败了

print "Setting result to FAILURE"
currentBuild.result = 'FAILURE'

print "Setting result to SUCCESS"
currentBuild.result = 'SUCCESS'

我猜这是故意的,“结果只会变得更糟”在:

//结果只会变得更糟
if(result==null | | r.isWorseThan(result)){
结果=r;
LOGGER.log(很好,这是“+getRootDir()+”中的+”:结果设置为“+r,LOGGER.isLoggable(Level.FINER)?新异常():null);
}

这是一个糟糕的工作,可以从另一个工作中执行

import com.cloudbees.groovy.cps.NonCPS
import jenkins.model.*
import hudson.model.Result

@NonCPS
def getProject(projectName) {
    // CloudBees folder plugin is supported, you can use natural paths:
    // in a postbuild action use `manager.hudson`
    // in the script web console use `Jenkins.instance`
    def project = jenkins.model.Jenkins.instance.getItemByFullName(projectName)
    if (!project) {error("Project not found: $projectName")}
    return project
}

project = getProject('foo/bar')
build = project.getBuildByNumber(2443)
// build = project.getBuild(project, '2443')

build.@result = hudson.model.Result.SUCCESS
// build.@result = hudson.model.Result.NOT_BUILT
// build.@result = hudson.model.Result.UNSTABLE
// build.@result = hudson.model.Result.FAILURE
// build.@result = hudson.model.Result.ABORTED

对于更简单的答案,只需获取原始构建,并直接设置字段:

currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS

在@metajiji的答案上,您需要批准jenkins主配置中的
hudson.model.result
project.getBuildByNumber
命令

currentBuild.result = hudson.model.Result.FAILURE.toString()

您是否尝试过在单个
节点中执行整个脚本?
?刚刚尝试过,但行为相同。为什么不将其保存在变量中,然后在准备好后进行设置?其思想是通过将“传播”设置为忽略管道中作业的结果false@MarcusUA我怎么能忽略一个阶段的结果,不是外部工作?@VadimKotov忽略阶段内每个工作的结果。这就是我的工作。一个插件(NUnit Publishing)通过“build.setResult”方法将阶段结果设置为“不稳定”,因此错误捕获无法工作。将此添加到阶段末尾完成了工作。是的,就是这个。TextFinder插件没有实现这一点是一件微不足道的事情,有了它,您可以将build设置为“不稳定”,而不是“构建”或“成功”。。。