node {
// Check the input build no exits or not
stage('Check the Valid Build Number') { // for display purposes
def jenkins = Jenkins.getInstance()
def jobName = "Demo"
def job = jenkins.getItem(jobName)
def BuildNo = "${BUILD_NUMBER}"
println "Last successfull build: ${job.getLastSuccessfulBuild()}"
def allbuild = "${job.getBuilds().collect{ it.getNumber()}}"
if(allbuild.contains(BuildNo)){
println "We found the build number entered by you in the build history: ${BuildNo}"
}
else
{
println "No build number was found "
error("Build failed because of this and that..")
}
}
stage('Rollback to Dev') {
println "Rollback to Dev is completed"
}
}