Skip to content

Instantly share code, notes, and snippets.

View TheDauthi's full-sized avatar

Billy W Conn TheDauthi

View GitHub Profile
@TheDauthi
TheDauthi / jenkins-recursive-delete.groovy
Last active May 15, 2021 09:16
Delete all Jenkins builds recursively older than a certain count
import hudson.model.*
keepCount = 10
// Some plugins - like the CB Folders - don't actually have builds. Filter them
jobs = Hudson.instance.getAllItems().findAll {
job -> job.hasProperty("lastBuild")
}
for(job in jobs)
{
lastBuildNumber = job.lastBuild.number
@TheDauthi
TheDauthi / show-scm-path.groovy
Last active May 29, 2017 06:15
Gets a list of SCMs in use by Jenkins. Displays the list of remote configs.
import hudson.model.*
// Only detect jobs that have the SCM property available
jobs = Hudson.instance.getAllItems().findAll {
job -> job.hasProperty("scm")
}
// Cheap formatting hack =)
maxWidth = Collections.max(jobs.collect { job -> job.fullName.length() })
@TheDauthi
TheDauthi / find-env-ports.sh
Created February 25, 2015 02:17
Find PORT settings inside foreman .env files.
find /srv/git -iname HEAD -prune -execdir sh -c 'git ls-tree -r HEAD --name-only | grep .env | xargs -I{} sh -c "git cat-file blob master:{} | awk -vREPO=$(pwd) -vFILE={} -vSEP=\# \"{ print REPO SEP FILE, \\\$0 }\" " ' \; | grep PORT | awk '{print $2, $1}' | sed -e 's/\/srv\/git\///' -e 's/.git\#.*//' | sort
# Installs Bundler (or whatever gem you want) for each version of ruby you have installed.
for i in $(rbenv versions --bare ); do rbenv shell $i; gem install bundler; done;
# Allows repeated partial application without automatic dispatch
class PartiallyAppliedMethod < Proc
def apply(*curried_args)
(@curried_args ||= []).push(*curried_args)
self
end
def call(*params)
super(*@curried_args, *params)
end
@TheDauthi
TheDauthi / dockerhost.sh
Last active March 5, 2018 21:00
Dockerhost detection
#!/usr/bin/env sh
# The default hostname to set
DEFAULT_DOCKER_HOSTNAME=${DEFAULT_DOCKER_HOSTNAME-dockerhost.internal}
# A comma-delimited list of extra hostnames to add as aliases
EXTRA_DOCKER_HOSTNAMES=${EXTRA_DOCKER_HOSTNAMES-}
# Whether to export variables
EXPORT_DOCKERHOST=${EXPORT_DOCKERHOST-1}
@TheDauthi
TheDauthi / Readme.md
Created March 7, 2018 18:52
Using a composer.json inside the vendor directory

This is how you create a composer.json that places itself inside the (managed) vendor directory Very simple, but I didn't find an example while searching, and I want to remind myself that I can do this.

Place this file inside the vendor directory. The following would be an example project structure

+- /project
   +- /lib
@TheDauthi
TheDauthi / jenkins-delete-all-builds.groovy
Created October 7, 2019 03:30
Remove all jenkins builds
jobs = Jenkins.instance.getAllItems(AbstractProject.class).collect {it -> Jenkins.instance.getItemByFullName(it.fullName) }
for(job in jobs) {
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
}