Skip to content

Instantly share code, notes, and snippets.

View batmat's full-sized avatar
😞
I may be very very slow to respond.

Baptiste Mathus batmat

😞
I may be very very slow to respond.
View GitHub Profile
@batmat
batmat / awaitility-demo.java
Created December 1, 2017 15:46
Awaitility quick demo code
* Java source, ASCII text
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
@batmat
batmat / pipeline-jdk9-failfast.md
Created September 1, 2017 23:36
Pipeline failing immediately when started running Jenkins on a JDK 9
Démarré par l'utilisateur admin
java.lang.IllegalArgumentException
	at org.kohsuke.asm5.ClassReader.<init>(ClassReader.java:170)
	at org.kohsuke.asm5.ClassReader.<init>(ClassReader.java:153)
	at org.jenkinsci.bytecode.helper.ClassLoadingReferenceTypeHierachyReader.reader(ClassLoadingReferenceTypeHierachyReader.java:64)
	at org.jenkinsci.bytecode.helper.TypeHierarchyReader.hierarchyOf(TypeHierarchyReader.java:176)
	at org.jenkinsci.bytecode.helper.ClassLoadingReferenceTypeHierachyReader.hierarchyOf(ClassLoadingReferenceTypeHierachyReader.java:39)
	at org.jenkinsci.bytecode.helper.TypeHierarchyReader$TypeHierarchy.isAssignableFrom(TypeHierarchyReader.java:321)
	at org.jenkinsci.bytecode.helper.TypeHierarchyReader$TypeHierarchy.isAssignableFromAnyInterfaceImplementedBy(TypeHierarchyReader.java:329)
import groovy.json.*
def slurper = new groovy.json.JsonSlurper()
def result = slurper.parse(new File('jvms.json'))
def vget(def map, def key) {
map.get(key) ?: "0"
}
final def JVM_VERSIONS = ["1.5", "1.6", "1.7", "1.8", "1.9"]
@batmat
batmat / find-non-dslized-jobs.groovy
Created April 15, 2016 14:52
Find non-JobDSLized Jenkins jobs - System Groovy Script
def generatedItemNames =
Jenkins.instance.getExtensionList('javaposse.jobdsl.plugin.DescriptorImpl')[0].generatedJobMap.keySet()
def adminItems = Jenkins.instance.items
.findAll { it.name.startsWith('admin-') || it.name.startsWith('forge-') || it.name.contains('marmotte') }
.collect { it.name }
def nonDslized = adminItems
.findAll { !generatedItemNames.contains(it) }
@batmat
batmat / map-to-json.groovy
Created February 12, 2016 12:41
Sample Groovy code to transform a Map into a Json output
def someMap = [
'key1': "value",
'key2': 142.1
]
def json = new groovy.json.JsonBuilder()
json rootKey: someMap
println "json output: "
@batmat
batmat / jenkins-computer-api-sample.json
Last active January 23, 2016 20:14
Sample output a call to http://localhost:8080/computer/api/json on a Jenkins 1.625.3
{
"busyExecutors": 0,
"computer": [
{
"actions": [],
"displayName": "maître",
"executors": [
{},
{}
],
@batmat
batmat / jenkins-plugins-with-gh-issues.list
Created December 12, 2015 19:33
Jenkins plugins having enabled gh issues...
cat repos.jenkins| jq -r '.[] | "\(.name) \(.has_issues)"' | grep -e '-plugin' | grep true | sort | sed 's/ true//'
allure-plugin
antexec-plugin
appdynamics-plugin
archived-artifact-url-viewer-plugin
artifact-promotion-plugin
audit2db-plugin
aws-beanstalk-publisher-plugin
aws-credentials-plugin
azure-publishersettings-credentials-plugin
@batmat
batmat / docker-swarm-create.sh
Created December 7, 2015 20:20
Simple docker swarm creation script
#!/bin/bash
NODECOUNT=2
SWARM_DISCOVERY="token://$(docker run --rm swarm create)"
DRIVER="--driver digitalocean --digitalocean-access-token="$(cat ~/.docker/digitaloceantoken)
#DRIVER="--driver virtualbox"
#DIGITALOCEAN_SIZE=64gb
docker-machine create \
@batmat
batmat / push_docker_swarm_stats.groovy
Last active November 24, 2015 15:56
Quick & certainly fragile script to gather informations from a docker swarm daemon /info Cf. https://github.com/docker/swarm/issues/735 for the clean way some day. Push to graphite also supported (see the end of the script)
// Quick & certainly fragile script to gather informations from a docker swarm daemon /info
// Cf. https://github.com/docker/swarm/issues/735 for the clean way some day
import groovy.json.*
def swarmInfoUrl = 'http://sv-t-vnl-ic-swarm:3375/info'
def graphiteHost = 'sv-t-vnl-forge-metrics'
def graphitePort = 2003
def nodeReservedMemoryField = 'reservedmemory'
def nodeTotalMemoryField = 'totalmemory'
@batmat
batmat / get-jenkins-build-time.groovy
Last active June 3, 2024 04:27
Quick Jenkins system groovy script to compute how many minutes of build you had in the last N hours
def numberOfHoursBack = 7*24
def totalBuildTime =
Jenkins.instance.getItems(Job.class).collect { job ->
job.getBuilds().byTimestamp(System.currentTimeMillis()-numberOfHoursBack*60*60*1000, System.currentTimeMillis())
}
.flatten()
.collect { build -> build.getDuration() }
.sum()