Skip to content

Instantly share code, notes, and snippets.

View stephenc's full-sized avatar
🍵
Enjoying a nice cup of tea

Stephen Connolly stephenc

🍵
Enjoying a nice cup of tea
View GitHub Profile
@stephenc
stephenc / README.md
Last active May 4, 2018 13:36
Watch Me Code, Episode 5 pipeline shared libraries

Watch Me Code - Episode 5

The build is defined in the vars/asfMavenTlpStdBuild.groovy file, that relies on the jenkinsEnv singelton.

Ideally you would put vars/jenkinsEnv.groovy in a separate repository (or at least a separate branch) and define two shared libraries:

  1. The shared library that defines jenkinsEnv
  2. The shared library that defines asfMavenTlpStdBuild

This way, to migrate to a different Jenkins master, we just need a different jenkinsEnv singleton that respects the same API contract.

@stephenc
stephenc / jenkins-43507.groovy
Created June 19, 2017 13:14
JENKINS-43507: Script to capture pre- and post- upgrade state of Multibranch projects and organization folders
println("Organization folder last scan");
println("=============================");
println();
for (def i in Jenkins.instance.allItems) {
if (i instanceof jenkins.branch.OrganizationFolder) {
println("${i.fullName}: ${i.computation.timestamp.format('yyyy-MM-dd HH:mm:ss z')} ${i.computation.result}");
}
}
println();
@stephenc
stephenc / gist:09b771c57126165d64495d6a0d43d237
Created March 23, 2017 17:06
Help rescue Jenkins in memory data to disk
for (def u in User.byName.values()) { u.save() }
for (def item in Jenkins.instance.allItems) { item.save() }
for (def c in Jenkins.instance.computers) { if (!(c instanceof hudson.model.Hudson$MasterComputer)) c.getNode().save() }
def listener=ExtensionList.lookup(AsyncPeriodicWork.class).get(org.apache.jenkins.gitpubsub.GitPubSubPoll.class);
println("Listener: ${listener}");
println("Listener.periodSeconds: ${listener.periodSeconds}");
println("Listener.requestRecycleMins: ${listener.requestRecycleMins}");
println("Listener.disableNotifyScm: ${listener.disableNotifyScm}");
println("Listener.lastTS: ${listener.lastTS}");
println("Listener.lastTime: ${listener.lastTime}");
println("Listener.longPollRequest: ${listener.longPollRequest}");
@stephenc
stephenc / JSONStringMap.java
Last active November 20, 2020 14:18
Very basic Java methods to encode/decode Map<String,String> as JSON
public static String write(Map<String, String> map) {
StringBuilder b = new StringBuilder();
b.append('{');
boolean first = true;
for (Map.Entry<String, String> e : map.entrySet()) {
if (first) {
first = false;
} else {
b.append(',');
}
usejava ()
{
local sel=$1.jdk
if [ -x "/Library/Java/JavaVirtualMachines/jdk$sel/Contents/Home/bin/java" -a ! -x "/Library/Java/JavaVirtualMachines/$1/Contents/Home/bin/java" ]
then
sel=jdk$sel
fi
local base=/Library/Java/JavaVirtualMachines
if [ -x "/System/Library/Java/JavaVirtualMachines/$sel/Contents/Home/bin/java" ]
then

Keybase proof

I hereby claim:

  • I am stephenc on github.
  • I am stephenconnolly (https://keybase.io/stephenconnolly) on keybase.
  • I have a public key whose fingerprint is 042B 29E9 2899 5B9D B963 C636 C7CA 19B7 B620 D787

To claim this, I am signing this object:

<server>
<id>junit.github.io</id>
<username>git</username>
</server>
@stephenc
stephenc / loatStatistics.groovy
Last active December 25, 2015 21:18
Estimates the number of executors in use for a Jenkins instance
def int x0 = 0;
def double x1 = 0.0;
def double x2 = 0.0;
println("Total executors")
println("===============")
println("")
println("Sampling every hour")
println("-------------------")
println("")
for (x in Jenkins.instance.overallLoad.totalExecutors.hour.history) {
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<com.cloudbees.jenkins.plugins.securecopy.ExportsJobProperty>
<exports/>
</com.cloudbees.jenkins.plugins.securecopy.ExportsJobProperty>
<hudson.model.ParametersDefinitionProperty>