Skip to content

Instantly share code, notes, and snippets.

<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"]
@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")
@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 / 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 / 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 / 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 / dockerps.sh
Created June 8, 2018 07:38
A customised docker ps with some extra information. Some techniques are used: (1) use `#xxx` as inline comments (2) use sed to filter lines (3) use awk to add new columns (4) use docker ps -format to get ps info we need (5) pass a bash variable to awk with -v option (6) force awk and column to use 'tab' as seperator instead of 'space'
#!/bin/bash
# Get ip address of this machine
ipAddress="$(/sbin/ip -o -4 addr list eth0 2> /dev/null | awk '{print $4}' | cut -d/ -f1)"
if [ "$ipAddress"=="" ]; then
ipAddress="$(/sbin/ip -o -4 addr list enp0s3 2> /dev/null | awk '{print $4}' | cut -d/ -f1)"
fi
# List containers
(
@askalee
askalee / dockerenv.sh
Created June 8, 2018 08:18
Get docker container environment variables
#!/bin/bash
containerName=$1
echo "containerName: $containerName"
if [ "$containerName" == "" ]; then
echo "USAGE: $0 containerName"
echo " containerName: id or name"
exit 1
fi
docker inspect -f \
@askalee
askalee / git-move-files-in-subfolder.md
Last active June 21, 2018 05:10 — forked from ajaegers/git-move-files-in-subfolder.md
Git: move files in an subfolder keeping history

Change structure of project folder with Git

I have this structure:

 project-folder/
     .git
     wp-admin/
     wp-content/
     wp-includes/

.htaccess

@askalee
askalee / gist:71be4a4ca3fa5195add85a50f027711f
Created June 21, 2018 05:54
plantuml: Group items with a hidden package for better layout
' reference: http://forum.plantuml.net/3648/invisible-packages-improve-layout-diagrams-visible-packages
@startuml
skinparam shadowing false
'skinparam backgroundColor red
skinparam package {
fontColor blue
stereotypeFontColor red
}
skinparam package<<Layout>> {