Skip to content

Instantly share code, notes, and snippets.

@utopius
utopius / script.groovy
Created June 7, 2016 07:15 — forked from retronym/script.groovy
jenkins job cloning
def projects = [
"scala-nightly-checkinit",
"scala-nightly-main",
"scala-nightly-rangepos",
"scala-nightly-windows"
]
inst = jenkins.model.Jenkins.instance;
def oldVersion = "2.10.x"
def newVersion = "2.11.x"
Jenkins.instance.items.findAll {job->
job.name.startsWith('<prefix-of-the-jobs>')//add the starting string - name of the job
}.each {
item ->
if (item.disabled == false) {
println item.name
item.disabled=true
item.save()
}
@utopius
utopius / exportShortGitCommit.groovy
Created June 7, 2016 07:29 — forked from fabito/exportShortGitCommit.groovy
Exporting short git commit sha1 hash in Jenkins through System Groovy Script build step
import hudson.model.*
def env = build.getEnvironment()
def gitCommit = env['GIT_COMMIT']
def shortGitCommit = gitCommit[0..6]
def pa = new ParametersAction([
new StringParameterValue("SHORT_GIT_COMMIT", shortGitCommit)
])
@utopius
utopius / jenkins-clean-slave-workspaces.groovy
Created June 7, 2016 07:30 — forked from stuartcampbell/jenkins-clean-slave-workspaces.groovy
A jenkins script to clean up workspaces on slaves which have < 10GB of free space
// Check if a slave has < 10 GB of free space, wipe out workspaces if it does
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
for (node in Jenkins.instance.nodes) {
@utopius
utopius / build-report.groovy
Created June 7, 2016 08:15 — forked from x-cray/build-report.groovy
Jenkins email-ext plugin groovy template. Generates build report. Based on http://techkriti.wordpress.com/2008/08/30/using-groovy-with-hudson-to-send-rich-text-email/
<!DOCTYPE html>
<head>
<title>Build report</title>
<style type="text/css">
body
{
margin: 0px;
padding: 15px;
}
@utopius
utopius / cleanupUnusedWorkspaceInSlaves.groovy
Created June 7, 2016 08:25 — forked from ceilfors/cleanupUnusedWorkspaceInSlaves.groovy
When you delete jobs in Jenkins, the corresponding workspaces in the build slaves won't be deleted automatically. This Jenkins script will go to each slave and check if the jobs are already deleted in Jenkins master and delete the workspace.
import com.cloudbees.hudson.plugins.folder.Folder
import hudson.FilePath
import jenkins.model.Jenkins
def boolean isFolder(String name) {
def item = Jenkins.instance.getItemByFullName(name)
return item instanceof Folder
}
def deleteUnusedWorkspace(FilePath root, String path) {
@utopius
utopius / update-svn-location.groovy
Created June 7, 2016 08:30 — forked from mdr/update-svn-location.groovy
Update SVN URL in Jenkins
import hudson.scm.*
newURL = "https://mvld-dev1.hcuk.pri:18080/svn/dev/hccf/test_automation/functional/trunk/selenium-framework/hitachi-automation"
for (job in Hudson.instance.items) {
if (job.scm instanceof SubversionSCM) {
location = job.scm.locations[0]
println(location)
newLocation = new SubversionSCM.ModuleLocation(newURL, location.local)
newscm = new SubversionSCM([newLocation], job.scm.workspaceUpdater, job.scm.browser,