How to manipulate the build result of a Jenkins pipeline job (back to 'SUCCESS')?

前端 未结 5 1540
温柔的废话
温柔的废话 2020-11-28 14:20

I\'m having some trouble to manipulate the build result of a Jenkins pipeline. I\'ve narrowed it down to the following issue: anyone know why the following Jenkins pipeline

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 15:00

    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
    

提交回复
热议问题