Skip to content

Instantly share code, notes, and snippets.

@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,
@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 / 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 / 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 / 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)
])
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 / 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"
@utopius
utopius / TransitionLinkedIssues
Created October 26, 2013 14:33
JIRA Script Runner groovy post-function which transitions linked issues with the given link type to the given step.Still needs some improvement.Put into atlassian-jira\WEB-INF\classes\com\onresolve\jira\groovy\canned\workflow\postfunctionsTo update you may have to edit a workflow transition -> add postfunction -> select ResolveLinkedIssues. This…
package com.onresolve.jira.groovy.canned.workflow.postfunctions
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ErrorCollection
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
@utopius
utopius / subversion.hook.mergeinfo
Last active December 19, 2015 11:49
Subversion / VisualSVN-Server batch pre-commit hook enforcing commit message length and forbidding addition of mergeinfo. Thx to HG :)
setlocal enabledelayedexpansion
set REPOS=%1
set TXN=%2
set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"
SET M=
REM Concatenate all the lines in the commit message
@utopius
utopius / jenkins.jira.latestVersion
Created June 2, 2013 02:16
Groovy script which fetches the latest unreleased version from Jira and adds it to the environment variables of a jenkins job. Can be used with scriptler and takes the jira url, username, password and the Jira project key as parameter.
import groovy.json.JsonSlurper;
import hudson.model.*;
def jiraUrl = "https://${url}/rest/api/2/project/${project}/versions/";
def conn = jiraUrl.toURL().openConnection();
def authString = "${user}:${password}".getBytes().encodeBase64().toString()
conn.setRequestProperty("Authorization", "Basic ${authString}");
if( conn.responseCode == 200 ) {
def versions = new JsonSlurper().parseText(conn.content.text);