This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This script shows how to get basic information about a job and its builds*/ | |
def jenkins = Jenkins.getInstance() | |
def jobName = "myJob" | |
def job = jenkins.getItem(jobName) | |
println "Job type: ${job.getClass()}" | |
println "Is building: ${job.isBuilding()}" | |
println "Is in queue: ${job.isInQueue()}" | |
println "Last successfull build: ${job.getLastSuccessfulBuild()}" | |
println "Last failed build: ${job.getLastFailedBuild()}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This script shows how to get see which Actions a job has, and how to get an Action instance */ | |
def jenkins = Jenkins.getInstance() | |
def jobName = "myJob" | |
def job = jenkins.getItem(jobName) | |
println "Job's actions: ${job.getActions()}" //The result is depended on which Jenkins plugins are installed | |
println "ParametersDefinitionProperty instance: ${job.getAction(hudson.model.ParametersDefinitionProperty.class)}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This script prints builds by their result */ | |
def jenkins = Jenkins.getInstance() | |
def jobName = "myJob" | |
def job = jenkins.getItem(jobName) | |
results = ["SUCCESS","UNSTABLE","FAILURE","ABORTED"] | |
def builfdByResult = { result -> job.getBuilds().findAll{ it.getResult().toString() == result} } | |
results.each { res -> | |
println "Builds ended with result ${res}" | |
println builfdByResult(res) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This scripts shows how to get and print basic information about a specific build */ | |
def jenkins = Jenkins.getInstance() | |
def jobName = "myJob" | |
int buildNumber = 186 | |
def job = jenkins.getItem(jobName) | |
//get the build | |
def bld = job.getBuildByNumber(buildNumber) | |
//print some of the builds info | |
println "Build type: ${bld.getClass()}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This script prints all labels of each unix slave */ | |
def jenkins = Jenkins.getInstance() | |
def nodes = jenkins.getNodes() | |
def unixNodes = nodes.findAll{ it.getComputer().isUnix()} | |
unixNodes.each{ | |
println it.getLabelString() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jenkins = Jenkins.getInstance() | |
def jobList = ["job1", "job2", "job3"] | |
//time frame is for example, you should choose a start build and an end build and take their timestamps | |
long startFrameTime = 1475758795672L | |
long endFrameTime = 1475779098244L | |
jobList.each{ jobName -> | |
def job = jenkins.getItem(jobName) | |
def bld = job.getBuilds().byTimestamp(startFrameTime,endFrameTime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The following script will add an information badge to the build. (use with groovy post build plugin) | |
def gitRepo = manager.build.buildVariableResolver.resolve('GIT_REPOSITORY') | |
def gitBranch = manager.build.buildVariableResolver.resolve('GIT_BRANCH') | |
manager.addBadge("text.gif", "$gitRepo / $gitBranch") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The scripts show how to enable and disable all jobs in a Jenkins folder | |
def jenkins = Jenkins.getInstance() | |
def folder = jenkins.getItem("test-folder") | |
def jobs = folder.getAllJobs() | |
disableJobs = jobs.each { | |
println "Disabled: ${it.isDisabled()}" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This script can be used in order to decrypt password from Jenkins' credentials.xml file | |
//The passwords in the file are hashed using Jenkins' key. In order to un-hash them: | |
// 1.Copy the required password | |
// 2. open Jenkins script console http://your-jenkins/script | |
// 3. exectue the following code: | |
def ENCRYPTED_PASSWORD = "paste the password here" | |
println( hudson.util.Secret.decrypt("${ENCRYPTED_PASSWORD}") ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.tasks.test.AbstractTestResultAction; | |
import hudson.tasks.junit.ClassResult; | |
import hudson.tasks.test.TabulatedResult; | |
import hudson.tasks.test.TestResult; | |
def jenkins = Jenkins.instance | |
def job = jenkins.getItem("your job") | |
def buildNum = 123 | |
def bld = job.getBuildByNumber(buildNum) | |
//println bld.actions |