Home > Blockchain >  Jenkins get last successful build tag
Jenkins get last successful build tag

Time:10-07

How to get Jenkins last successful build number? I tried a few ways and none of them are working..

I'm using Jenkins 2.309

/api/xml doesn't have Last successful build either.

def buildNumber = Jenkins.instance.getItem('jobName').lastSuccessfulBuild.number doesn't return anything and the step files.

And then I tried this but it doesn't return the number.

                    catchError {
                        script {

                            def jenkins = Jenkins.getInstance()
                            def jobName = "demo-spring-boot"
                            def job = jenkins.getItem(jobName)

                            println "Last successfull build: ${job.getLastSuccessfulBuild()}"
                        }
                    }

It returns Last successfull build: null

I checked the job history and it does have few succssful builds

CodePudding user response:

def lastSuccessfulBuildId = currentBuild.previousSuccessfulBuild?.id
println lastSuccessfulBuildId

(I put ? because there could be no successful builds)

  • Related