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 code replaces a value of a property in a property file, while keeping comments if exist | |
def fileName = 'test.properties' | |
def propertyKey = 'key' | |
def myFile = new File(fileName) | |
def fileText = myFile.text | |
matcher = fileText=~propertyKey+"=(.*)" | |
result = matcher.replaceFirst(propertyKey+'=new value') | |
myFile.withWriter { myFile << result } |
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 numOfMonths = 4 | |
Calendar calendar = Calendar.getInstance(); | |
calendar.add( Calendar.MONTH, numOfMonths * -1 ); | |
def threeMonthsAgo = calendar.getTime() | |
def filterClosure = { job -> ((job.getLastBuild()?.timestamp?.time?.before(threeMonthsAgo) && job.getLastBuild() != null) | |
&& job.name.toLowerCase().contains('-Branch-'.toLowerCase()) && job.name.toLowerCase().startsWith('MaaS'.toLowerCase()) | |
&& !job.name.toLowerCase().contains('Infra'.toLowerCase()) && !job.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
def jobName = 'MyJob' | |
def paramNamesAndValues = 'param1=value1¶m2=value2¶m3=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 -> |
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 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()}") |
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 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); |
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 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" |
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.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 -> |
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 project = jenkins.getItem("Git-plugin-test") | |
def bld = project.getLastBuild() | |
def scm = project.scm | |
def data = scm.getBuildData(bld,false) | |
data.getLastBuiltRevision() |
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
//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) |
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 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()}" |
OlderNewer