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
//return all slave labels | |
Jenkins.instance.labels |
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 comp = Jenkins.instance.getComputer(computerName) | |
//print all executors | |
comp.getExecutors()..each{ | |
println it | |
} | |
//kill with condition (for example executor with number == 1 | |
comp.getExecutors().findAll{ it.number == 1}.each{ | |
it.finish2() | |
} |
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 |
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
//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
//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
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
/* 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
/* 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 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) |