That's works and can be executed from another job!
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