Skip to content

Instantly share code, notes, and snippets.

View vishalTrivedi88's full-sized avatar

Vishal vishalTrivedi88

  • NortonLifeLock Inc.
  • Pune
View GitHub Profile
hudson = hudson.model.Hudson.instance
hudson.slaves.each {
if(it.remoteFS.contains("C:")){
it.labelString = it.labelString+ " "+"windows"
}else{
it.labelString = it.labelString+ " "+"non_windows"
}
}
hudson.save()
@vishalTrivedi88
vishalTrivedi88 / ConnectDisconnectAllNodes.groovy
Created May 23, 2020 13:49
Jenkins groovy script to connect or Disconnect All Jenkins nodes.
for (aSlave in hudson.model.Hudson.instance.slaves) {
computer = aSlave.getComputer();
// println computer
computer.setTemporarilyOffline(true) // To Disable all Nodes
// computer.setTemporarilyOffline(false) -- To Enable all nodes.
}
@vishalTrivedi88
vishalTrivedi88 / CheckSlaveOnline.groovy
Created May 23, 2020 10:51
Jenkins script to bring slave online. The job would wait for 10 mins if the slave doesnt come online within that time it ll fail.
import hudson.model.*
import hudson.AbortException;
def resolver = build.buildVariableResolver
// def node_names = resolver.resolve("NODE_LIST").split(",")
timeout_seconds = 600 // 10 mins
sleepTime=30 // seconds
def node_name=resolver.resolve("NODE_NAME").replaceAll("\\s","")
slave = Hudson.instance.slaves.find({it.name == node_name});
@vishalTrivedi88
vishalTrivedi88 / ArchiveJenkinsJobs.groovy
Created May 23, 2020 10:49
Move Jenkins jobs which are N months old to a specific(Archive) folder.
import jenkins.model.Jenkins
import hudson.model.*
//get jenkins env var
thr = Thread.currentThread()
build = thr.executable
myVar = build.getEnvironment(listener).get('Months')
months= Integer.parseInt(myVar )
@vishalTrivedi88
vishalTrivedi88 / UpdateAllNodeConfig.groovy
Created May 23, 2020 10:45
Jenkins script that will update a certain config in all the available nodes.
import hudson.model.*
import hudson.slaves.*
import hudson.util.*
import jenkins.model.*
def resolver = build.buildVariableResolver
def old_string = resolver.resolve("OLD_STRING")
def new_string = resolver.resolve("NEW_STRING")
import hudson.model.*
int jobs=0;
long time=0;
hudson.model.Hudson.getInstance().getAllItems(Job.class).each {
build = it.getLastBuild()
if(build){
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
if(action){
jobs++
@vishalTrivedi88
vishalTrivedi88 / labels_node.groovy
Created August 14, 2019 07:46
This script is a jenkins groovy script that would give the list of labels and nodes associated with it.
import static groovy.json.JsonOutput.*
def labels=[]
def lbl_node=[:]
for (aSlave in hudson.model.Hudson.instance.slaves) {
tmp_lbl = aSlave.getLabelString().toString()
// println lbl
lbls=tmp_lbl.split(" ")
for (lbl in lbls){