Skip to content

Instantly share code, notes, and snippets.

@askalee
askalee / RunCommand.groovy
Created May 30, 2018 09:28
Groovy run command, get stdout stderr and exit code
cmd = "./restart.sh ${server} ${containerName}"
println("INFO: Restarting the container: ${cmd}")
def proc = cmd.execute()
proc.waitForProcessOutput(System.out, System.err)
def errorCode = proc.exitValue()
@askalee
askalee / DynamicParallelSteps.groovy
Last active May 23, 2018 05:19
Dynamic parallel steps (Declarative Pipeline)
pipeline {
agent { label "linux"}
stages {
stage('1') {
steps {
script {
def tests = [:]
for (f in ['a', 'b']) {
tests["${f}"] = {
node('linux') {
@askalee
askalee / JenkinsGroovyUnitTest
Created October 23, 2017 06:54
Run unit test each time before the main script runs
def RunUnitTests() {
println("INFO: Running Unit Tests")
def tests = [:]
// define unit tests here
tests["GetNodesByLabel"] = {
assert GetNodesByLabel().collect{it.name}.size() > 0
}
@askalee
askalee / CheckSlaveFreeSpace
Last active November 18, 2021 12:50
Monitor jenkins slave disk space
// https://gist.github.com/askalee/2148608fb4423d97ded690829daae173
// HISTORY:
// * 2017/10/19: show free disk size for all nodes
// * 2017/10/23: auto check nodes labeled with _autoClean
// * 2017/10/26: 1. monitor all nodes instead of only monitor specific nodes with certain label
// 2. catch exceptions
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
@askalee
askalee / gist:2c26aa57ca46efe2b1239da03c700497
Last active October 23, 2017 02:23 — forked from rb2k/gist:8372402
A jenkins script to clean up workspaces on slaves
// https://gist.github.com/askalee/2c26aa57ca46efe2b1239da03c700497
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
def DEBUG_MODE = (build.getEnvironment(listener).get('DEBUG_MODE') == "true")
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*
[System
[Provider
[@Name='Microsoft-Windows-Security-Auditing']
and
TimeCreated[timediff(@SystemTime) &lt;= 86400000]
]
and EventData[Data="joe"]