Skip to content

Instantly share code, notes, and snippets.

@tknerr
tknerr / Jenkinsfile
Last active February 27, 2017 08:17
Trying to run steps on many slaves in parallel, but when the `doStuff(x)` closure is executed the slave name argument being passed (`x`) is always "slave3"
def onEachSlave(doStuff) {
def doStuffClosures = [:]
for (slave in ['slavelnx1', 'slavelnx2', 'slavelnx3']) {
def s = slave
doStuffClosures[s] = { echo "running on ${s}..."; doStuff(s); echo "...done on ${s}!" }
}
return doStuffClosures
}
parallel(onEachSlave { slave ->
echo "doing stuff on ${slave}..."
@tknerr
tknerr / get-plugins.sh
Created July 17, 2017 16:22
Get Jenkins Plugins + Versions via Jenkins XML API (and convert to copy/pasteable YAML format for Ansible ;-))
curl 'http://admin:admin@localhost:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins' \
| perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/- { name: \1, version: \2 }\n/g' \
| sort
@tknerr
tknerr / chefdk-install.log
Last active August 17, 2017 19:32
ChefDK doesn't install on Win 10 1703 - log output of `msiexec /i chefdk-windows-1.5.0.msi /l*V chefdk-install.log`
=== Verbose logging started: 8/18/2017 4:19:49 Build type: SHIP UNICODE 5.00.10011.00 Calling process: C:\Windows\system32\msiexec.exe ===
MSI (c) (D8:A0) [04:19:49:117]: Font created. Charset: Req=0, Ret=0, Font: Req=MS Shell Dlg, Ret=MS Shell Dlg
MSI (c) (D8:A0) [04:19:49:117]: Font created. Charset: Req=0, Ret=0, Font: Req=MS Shell Dlg, Ret=MS Shell Dlg
MSI (c) (D8:B4) [04:19:49:180]: Resetting cached policy values
MSI (c) (D8:B4) [04:19:49:180]: Machine policy value 'Debug' is 0
MSI (c) (D8:B4) [04:19:49:180]: ******* RunEngine:
******* Product: chefdk-windows-1.5.0.msi
******* Action:
@tknerr
tknerr / ci_jobs.groovy
Created October 6, 2017 10:00
JobDSL example for setting up master / release branch builds + PR builds via bitbucket-branch-source-plugin (using the generated JobDSL)
// define the bitbucket project + repos we want to build
def bitbucket_project = 'awesome'
def bitbucket_repos = ['foo','bar','baz']
// create a pipeline job for each of the repos and for each feature branch.
for (bitbucket_repo in bitbucket_repos)
{
multibranchPipelineJob("${bitbucket_repo}-ci") {
// configure the branch / PR sources
branchSources {
@tknerr
tknerr / Jenkinsfile.groovy
Last active February 29, 2020 05:54
Debugging Powershell Sequential / Parallel Workflows and Error Reporting in Jenkinsfile
def powershell_workflow(String mode, String... scripts) {
powershell """
echo "starting workflow in $mode mode"
workflow runWorkflow {
$mode {
${scripts.collect { script ->
"InlineScript { ${script} *>&1 | tee -filepath ${script.replace(' ','_')}.log; if(\$LastExitCode -ne 0) { Throw \"ERROR: \'$script\' failed with exit code \$LastExitCode \" } } -ErrorAction Continue"
}.join('\n') }
}
}
@tknerr
tknerr / ci_jobs.groovy
Created January 18, 2018 10:21
Example JobDSL for a multibranchPipelineJob which keeps only the last 10 builds
// define the bitbucket project + repos we want to build
def bitbucket_project = 'myproj'
def bitbucket_repos = ['myrepo1', 'myrepo2']
// create a pipeline job for each of the repos and for each feature branch.
for (bitbucket_repo in bitbucket_repos)
{
multibranchPipelineJob("${bitbucket_repo}-ci") {
// configure the branch / PR sources
branchSources {
@tknerr
tknerr / README.md
Created January 26, 2018 15:23
How to create a Visual Studio 2017 Offline Installer

README

A Visual Studio 2017 offline installer can be created with the following command:

vs_Professional.exe --layout C:\vs2017offline --add Microsoft.VisualStudio.Workload.CoreEditor --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.Azure --add Microsoft.VisualStudio.Workload.Data --add Microsoft.VisualStudio.Workload.NetCoreTools --includeRecommended --lang en-US de-DE

It includes the workloads and language packs specific for this project. You can easily create your own custom offline installer if your project uses a different toolchain.

@tknerr
tknerr / git-ps1.bash
Created February 28, 2018 06:42
A Git Bash Prompt for Ubuntu 16.04
#!/bin/bash
export PS1='`if [ $? = 0 ]; then echo "\[\e[32m\] ✔ "; else echo "\[\e[31m\] ✘ "; fi`\[\e[00;37m\]\u\[\e[01;30m\]@\[\e[00;37m\]\h\[\e[01;37m\]:\[\e[01;34m\]\w\[\e[00;34m\] `[[ $(git status 2> /dev/null | head -n3 | tail -n1) != "Changes to be committed:" ]] && echo "\[\e[01;31m\]" || echo "\[\e[01;33m\]"``[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] || echo "\[\e[01;32m\]"`$(__git_ps1 "(%s)")`echo "\[\e[00m\]"`\$ '
@tknerr
tknerr / output
Last active April 11, 2018 20:41
ping exercise in plain bash
$ ./pinger.sh "google.com facebook.com zuehlke.com"
average ping time for zuehlke.com: 63.600 ms
average ping time for facebook.com: 61.161 ms
average ping time for google.com: 61.953 ms
@tknerr
tknerr / actual-requests-vs-past-day-average.appinsights
Last active November 8, 2018 00:12
Show the actual requests of the past 5 minutes vs the average request count over the past day. The threshold we want to alert upon is the past day's average amplified by a factor of 10.
let lookbackWindow=30d;
let observationInterval=1d;
let sampleInterval=5m;
let thresholdFactor=10;
// 5-min request count average measured over the past 1 day
let averagedRequestsInObservationInterval = requests
| where timestamp > ago(lookbackWindow)
| summarize sum(itemCount) by bin(timestamp, sampleInterval)
| summarize averageRequestCount = avg(sum_itemCount) by bin(timestamp, observationInterval)
| extend threshold = averageRequestCount * thresholdFactor;