Skip to content

Instantly share code, notes, and snippets.

View rodrigozrusso's full-sized avatar

Rodrigo Russo rodrigozrusso

View GitHub Profile
#Bring back a Jenkins node thread from the ashes
# to use: export JENKINS_USERNAME="" and export JENKINS_PASSWORD=""
# Enjoy!
JENKINS_URL="http://localhost:8080";
NODE_PREFIX="ND-";
for ((node=1;node<=10;node++));
do
NODE_NAME=`printf "%s%02d" $NODE_PREFIX $node`
@rodrigozrusso
rodrigozrusso / gist:3d7e31de720b2d0df006
Created February 18, 2015 07:58
Create jenkins job based on template (groovy)
def jenkins = hudson.model.Hudson.instance
def template = jenkins.getItem("MyTemplate")
def job = jenkins.copy(template,"MyNewJob")
job.scm = new hudson.scm.SubversionSCM("http://base/branches/mybranche")
job.save()
@rodrigozrusso
rodrigozrusso / find_recursive_template.sh
Created July 31, 2015 07:57
Find jobs has the same job configured as template with ProxyBuilder plugin
cd /var/lib/jenkins/jobs;
for i in `find . -name "config.xml" | grep -v backup_config | xargs grep -i "hudson.plugins.templateproject.ProxyBuilder" | cut -d ":" -f 1`; do echo $i; job=`echo $i|cut -d "/" -f 2`; echo "job=$job"; cat $i | grep -i projectname | grep $job;done
@rodrigozrusso
rodrigozrusso / jenkins_logrotate.groovy
Last active June 16, 2022 15:13
Force log rotate in Jenkins
Jenkins.instance.getItemByFullName('<job-name>').each {
try {
println(it.logRotator.perform(it))
} catch (Exception e) {
println("It didn't work: "+ e)
}
}
@rodrigozrusso
rodrigozrusso / jenkins_print_out.groovy
Last active November 18, 2015 12:58
Weird way to write to standard jenkins output log in groovy
def config = new HashMap()
def bindings = getBinding()
config.putAll(bindings.getVariables())
def out = config['out']
new ClassA().testMe(out);
class ClassA {
void testMe(out) {
out.println('testMe');
}
@rodrigozrusso
rodrigozrusso / getJenkinsUrl.groovy
Created February 25, 2016 13:50
get-jenkins-url
def jlc = new jenkins.model.JenkinsLocationConfiguration();
println jlc.getUrl()
println jlc.getAdminAddress()
@rodrigozrusso
rodrigozrusso / jenkinsLoadJartoClasspath.groovy
Created February 26, 2016 08:37
jenkins Load Jar to Classpath
this.getClass().classLoader.rootLoader.addURL(new File("file.jar").toURL())
@rodrigozrusso
rodrigozrusso / jenkins_label_assigned.groovy
Created March 8, 2016 16:58
Assign label to all jobs in jenkins
import hudson.model.*
import hudson.model.labels.*
import hudson.maven.*
import hudson.tasks.*
import hudson.plugins.git.*
hudsonInstance = hudson.model.Hudson.instance
allItems = hudsonInstance.allItems
buildableItems = allItems.findAll{ job -> job instanceof BuildableItemWithBuildWrappers }
@rodrigozrusso
rodrigozrusso / 100-mesos.groovy
Created March 9, 2016 13:17 — forked from mrbobbytables/100-mesos.groovy
jenkins mesos dynamic config
#!/usr/bin/env groovy
/*
Fairly self explanatory if you look at the options in the UI.
Main thing to note is the JENKINS_MESOS_SLAVE_<number>. Anything with the same
number will be associated together option wise.
For things like JENKINS_MESOS_SLAVE_<number>_VOL_<number> The trailing
number just signifies more than one.
--Available Environment Variables --
Jenkins.instance.items.findAll {job->
job.name.startsWith('<prefix-of-the-jobs>')//add the starting string - name of the job
}.each {
item ->
if (item.disabled == false) {
println item.name
item.disabled=true
item.save()
}