Skip to content

Instantly share code, notes, and snippets.

View tizki's full-sized avatar

Tidhar Klein Orbach tizki

View GitHub Profile
@tizki
tizki / JenkinsJobActions.groovy
Last active September 7, 2016 19:04
This script shows how to get see which Actions a job has, and how to get an Action instance
/* 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)}"
@tizki
tizki / JenkinsJobInfo.groovy
Last active September 7, 2016 18:52
This script shows how to get basic information about a job and its builds
/*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()}"
@tizki
tizki / JenkinsInfo.groovy
Last active September 7, 2016 18:53
This scripts shows how to get basic information about Jenkins instance
/* This scripts shows how to get basic information about Jenkins instance */
def jenkins = Jenkins.getInstance()
println "Jenkins version: ${jenkins.getVersion()}"
println "Available JDKs: ${jenkins.getInstance().getJDKs()}"
println "Connected Nodes:"
jenkins.getNodes().each{
println it.displayName
}
println "Configured labels: ${jenkins.getLabels()}"
//posted at http://stackoverflow.com/a/37805003/947784
import jenkins.model.Jenkins
import hudson.model.*
def jenkins = Jenkins.getInstance()
def jobName = "yourJobName"
String versionType = "minor"
def job = jenkins.getItem(jobName)
def jenkins = Jenkins.getInstance()
def project = jenkins.getItem("Git-plugin-test")
def bld = project.getLastBuild()
def scm = project.scm
def data = scm.getBuildData(bld,false)
data.getLastBuiltRevision()
@tizki
tizki / printJobsPerThrottleCategory.groovy
Created January 24, 2016 10:03
groovy script that prints all job name per jenkins throttle plugin category
import hudson.plugins.throttleconcurrents.*
jenkins = Jenkins.getInstance()
ThrottleJobProperty.DescriptorImpl descriptor = jenkins.getDescriptorByType(ThrottleJobProperty.DescriptorImpl.class)
categories = descriptor.getCategories()
propertiesMap = descriptor.propertiesByCategory
propertiesMap.each { categoryName, subMap ->
println "******** Name ${categoryName} ********"
subMap.each {propertyName, value ->
@tizki
tizki / runningBuildsFromViewToSummary.groovy
Created January 23, 2016 18:39
jenkins groovy post build script that post links to running builds from a view with their elapsed time in minutes
/*
This script should be used in groovy post build
it posts a link to the running jobs with their duration
the job are taken from the view
*/
import hudson.model.*
import jenkins.model.Jenkins
MY_VIEW = "My-view"
def myView = Hudson.instance.getView(MY_VIEW)
currentJobName = "myJob"
@tizki
tizki / getBuildArtifactsByNameAndTime.groovy
Created November 19, 2015 13:19
Jenkins groovy script - get artifacts from build by name and time
def numOfMonths = 4
Calendar calendar = Calendar.getInstance();
calendar.add( Calendar.DAY_OF_MONTH, numOfMonths * -1 );
def filterTime = calendar.getTime()
def jobName = "MaaS-Job-Tests-Integration-Server-release-3.3"
def jen = Jenkins.getInstance();
def jobToClean = jen.getItem(jobName);
@tizki
tizki / bulkJobDisableByNames.groovy
Last active November 19, 2015 13:20
Jenkins groovy script - bulk disable non-disabled jobs by name
def jobToDisable = "MyJob1&MyJob2&MyJob3"
def j = Jenkins.getInstance()
jobs = jobToDisable.split("&")
//println("I: ${jobs}")
jobs.each{ jobName ->
try{
def job = j.getItem(jobName)
println(" ${jobName}: ${job.isDisabled()}")
@tizki
tizki / addParametersToJob.groovy
Last active November 19, 2015 13:21
Jenkins groovy script - adds parameters to a job
def jobName = 'MyJob'
def paramNamesAndValues = 'param1=value1&param2=value2&param3=value3'
def j = Jenkins.getInstance()
def job = j.getItem(jobName)
def new_param = []
def params
def getKeyValueMapFromData(data){
def result = data.split('&').inject([:]) {
map, token ->