This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.User | |
import jenkins.security.ApiTokenProperty | |
def username = 'my-username' | |
def tokens = ['my-api-token'] | |
user = User.get(username, false, Collections.emptyMap()) | |
if (user == null) { | |
println "Did not find existing user '${username}', creating it..." | |
user = User.get(username, true, Collections.emptyMap()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.yaml:snakeyaml:1.17') | |
import org.yaml.snakeyaml.Yaml | |
def lockableResourcesConfigFile = new File("${System.getenv('INIT_JENKINS_CONFIG')}/lockableResources.yml") | |
if (lockableResourcesConfigFile.exists()) { | |
println "INFO: Adding LockableResources from configuration: ${lockableResourcesConfigFile.absolutePath}" | |
Yaml parser = new Yaml() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.io.FileType | |
def initGroovyDir = new File("${System.getenv('JENKINS_HOME')}/init.groovy.d") | |
initGroovyDir.eachFileMatch(FileType.FILES, ~/.*\.groovy/) { | |
println "Running: ${it}" | |
new GroovyShell(this.class.classLoader).evaluate(it) | |
} | |
println "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox; default-src 'none'; img-src 'self'; style-src 'self' 'unsafe-inline';") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jenkins.plugins.lockableresources.LockableResources | |
import org.jenkins.plugins.lockableresources.LockableResource | |
import java.util.Date | |
def resourceManager = org.jenkins.plugins.lockableresources.LockableResourcesManager.get() | |
timestamp = new Date().time / 1000 as Integer | |
data = [:] | |
resourceManager.allLabels.each { label -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cat -vet log | sed -r 's/\^\[\[8m[a-z\:\/0-9A-Z\+]+={1,2}?\^\[\[0m//g' | sed 's/\$$//g' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def findPreviousSuccessfulBuild(build) { | |
previousBuild = build.previousBuild | |
while (previousBuild != null && previousBuild.result != Result.SUCCESS) { | |
previousBuild = previousBuild.previousBuild | |
} | |
return previousBuild | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printClassPath(classLoader) { | |
println "=== ${classLoader} ===" | |
if (classLoader instanceof java.net.URLClassLoader) { | |
classLoader.getURLs().each {url-> | |
println "- ${url.toString()}" | |
} | |
} | |
if (classLoader.parent) { | |
printClassPath(classLoader.parent) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plugins = Jenkins.instance.pluginManager.plugins.sort(mutate = false) { a, b -> a <=> b }.each { | |
println "${it.shortName}:${it.version}" | |
} | |
println "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobs = Jenkins.instance.allItems(hudson.model.Job).findAll { it.fullName == ("<JOBNAME>") } | |
jobs.each { job -> | |
job.builds.findAll { !it.building }.each { build -> | |
finished = new Date(build.timestamp.timeInMillis + build.duration) | |
println "${build} - ${build.result} (${finished})" | |
action = build.getAction(org.jenkinsci.plugins.workflow.job.views.FlowGraphAction) | |
action.getNodes().findAll { it.displayName.startsWith("") }.each { | |
if (it.displayName.startsWith("Building") && it.getError() != null) { | |
println "\t${it.displayName}" | |
} |
NewerOlder