Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Please comment & let me know if you have a fork / fixes you'd like to include.
{ | |
"defaultProfile": "{09dc5eef-6840-4050-ae69-21e55e6a2e62}", | |
"initialRows": 30, | |
"initialCols": 120, | |
"alwaysShowTabs": true, | |
"showTerminalTitleInTitlebar": true, | |
"experimental_showTabsInTitlebar": true, | |
"profiles": [ | |
{ | |
"guid": "{09dc5eef-6840-4050-ae69-21e55e6a2e62}", |
# generate a script ./clone-repos.sh from a list of repos fetched via Bitbucket API | |
# note: requires 'curl' and 'jq' to be installed | |
set -e | |
echo -n '' > clone-repos.sh | |
chmod +x clone-repos.sh | |
ONPREM_USER=xxxxx | |
ONPREM_PASS=...... |
// find old workspace folders on any node (master/slave) | |
// currently only look for deleted branches of multibranch (pipeline?) jobs, and remove them | |
// also finds builds older than 90 days. Set flags below to true to actually do deletes | |
import hudson.model.*; | |
import hudson.util.*; | |
import jenkins.model.*; | |
import hudson.FilePath; | |
import hudson.FilePath.FileCallable; | |
import hudson.slaves.OfflineCause; |
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) { |
// | |
// Jenkins Job DSL example to create build projects for Bitbucket branches | |
// | |
// Imports | |
import java.text.DateFormat | |
import java.text.SimpleDateFormat | |
import groovy.time.TimeCategory | |
// URL components |
Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Please comment & let me know if you have a fork / fixes you'd like to include.
// When using the Promoted Build plugin, you may want to perform some operations | |
// then you may also want to add badges or a summary to the target build as | |
// opposed to the promotion build. This script assumes that you have a manual | |
// promotion process with a parameter called RELEASE_VERSION (hence requiring | |
// user input); the content that follows would be what you put as a Groovy | |
// Postbuild action on the promotion process. | |
import org.jvnet.hudson.plugins.groovypostbuild.*; | |
def add_release_version(promotion) { |
Closure job = { | |
// Job Name | |
name "${stashProjectKey}-${projectName}-${branchSimpleName}" | |
// Where should jenkins run the job | |
label ('master') | |
// Where should Jenkins get the source code from | |
scm { | |
git { |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
jenkins-stats.py is used to generate statics for jenkins server, so far it display the plugin's usage in each job, see related stackoverflow question:how can I know whether the plugin is used by any jobs in jenkins
python-requests module is required