Skip to content

Instantly share code, notes, and snippets.

View gokart23's full-sized avatar

Karthik Duddu gokart23

View GitHub Profile
@gokart23
gokart23 / trigger_jenkins_pipeline_programmatically.java
Created January 18, 2018 16:55
Programmatically trigger a pipeline run (with custom data) in Jenkins
import jenkins.model.*;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.queue.QueueTaskFuture;
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction;
String text = "node('some-node') { echo 'hi'; }"
@gokart23
gokart23 / KubeConnect.java
Created January 3, 2018 14:16
Remove nodes from a Kubernetes deployment programatically, in order to potentially use the deployment as a pool of ready nodes
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@gokart23
gokart23 / convert_kubectl_events_to_local_tz.sh
Created January 1, 2018 13:38
Convert Kubernetes events to local timezone (for comparison with other logs)
kubectl get events -o json | jq '.items[] | .lastTimestamp + "," + .message' | tr -d '"' | awk -F',' '{cmd="date +\"%d/%b/%Y:%T\" --date=" $1; cmd | getline conv_date; print "[" conv_date "] (kubectl events) " $2}'
@gokart23
gokart23 / human_readable_time_to_ms.py
Created December 20, 2017 07:27
Convert human-readable time ('1 min 3 sec', '0.58 hr', etc) to milliseconds
interval_dict = OrderedDict([
('hr', 3600*1000),
('min', 60*1000),
('sec', 1000),
('ms' , 1),
])
def convert_to_ms(string):
interval_regex = re.compile( "^[<]?(?P<value>(\d\.)?[0-9]+) (?P<unit>({0}))".format("|".join(interval_dict.keys())) )
@gokart23
gokart23 / delete-slaves.groovy
Created December 11, 2017 07:54
Delete slaves with a certain label directly from Jenkins master script console
import hudson.slaves.*
import hudson.model.*
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.name.indexOf("medium-rt-framework") == 0 && !aSlave.getComputer().isOnline()) {
aSlave.getComputer().setTemporarilyOffline(true, null)
aSlave.getComputer().doDoDelete()
}
}