Skip to content

Instantly share code, notes, and snippets.

@ThabetAmer
Last active June 17, 2022 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThabetAmer/91cc801164a7677c99221e0efdc4b31b to your computer and use it in GitHub Desktop.
Save ThabetAmer/91cc801164a7677c99221e0efdc4b31b to your computer and use it in GitHub Desktop.
Groovy/Jenkins function to return the ID number of last successful build for a specific Jenkins job
#!/usr/bin/env groovy
/**
* Gets last successful build number
* @author thabet.amer@gmail.com
* @since Jenkins 2.204.1
* @param String job name
* @return String number of build number
*
*/
import jenkins.model.Jenkins
def getLastSuccessful(jobName) {
assert jobName != null
return Jenkins.getInstance().getItemByFullName(jobName).lastSuccessfulBuild.number
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment