Skip to content

Instantly share code, notes, and snippets.

@thomaschaplin
thomaschaplin / git-commit-search-cheat-sheet.md
Created August 21, 2025 11:40
Git Commit Search Cheat Sheet

Git Commit Search Cheat Sheet

Quick reference for finding commits in Git with examples.


1. Search by exact string (-S)

git log -p -S "" -- 
@thomaschaplin
thomaschaplin / README.md
Last active April 23, 2025 12:12
A simple Bash script to export all incidents from PagerDuty month by month basis.

PagerDuty Incident Exporter

A simple Bash script to export all incidents from PagerDuty month by month basis.

It:

  • Queries the PagerDuty Incidents API v2
  • Handles pagination (for large result sets)
  • Outputs one JSON file per month like pagerduty-incident-export-12-2021.json, pagerduty-incident-export-01-2022.json, etc.
  • Compatible with macOS (uses BSD date syntax)
@thomaschaplin
thomaschaplin / README.md
Created February 26, 2025 14:16
Unused CRD Detector for Kubernetes

Unused CRD Detector for Kubernetes

This script lists all Custom Resource Definitions (CRDs) in a Kubernetes cluster and checks how many instances exist for each CRD. It only prints CRDs that have at least one instance.

Prerequisites

  • kubectl
  • jq

Usage

@thomaschaplin
thomaschaplin / how-to-view-all-jenkins-secrets.md
Created May 23, 2023 12:28
How to view all Jenkins Secrets/Credentials

How to view all Jenkins Secrets/Credentials

I recently worked on a Project that required migrating Jenkins credentials to another credentials store, going to each credential and viewing and subsequently decrypting the credential turned into a real chore and I needed a way to do this all in one go.

Luckily we can access credentialsStore using Jenkins script console, so:

In Jenkins, go to: /script page. Run the following command:

def sout = new StringBuilder(), serr = new StringBuilder()
def proc = "ls /var/jenkins_home/jobs".execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(30000)
println "out> $sout\nerr> $serr"
@thomaschaplin
thomaschaplin / how-to-run-commads-on-jenkins-master.groovy
Created May 13, 2022 08:45
How to run commands on Jenkins master via script console
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = "git config --list".execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(30000)
println "out> $sout\nerr> $serr"
@thomaschaplin
thomaschaplin / how-to-delete-index-lock-file-in-jenkins.md
Last active August 24, 2023 10:29
How to delete an index.lock file in Jenkins

How to delete a index.lock file via the Script Console

Steps

Step 1

In the console output of the failing job you will see an error similar to - stderr: fatal: Unable to create '/var/jenkins_home/jobs/job-name-example/workspace@script/.git/index.lock': File exists.

Step 2

@thomaschaplin
thomaschaplin / kill-jenkins-job-via-script-console.md
Last active August 24, 2022 13:58
How to kill a Jenkins job via the script console

How to kill a Jenkins job via the Script Console

Steps

Step 1

Find the name of the job, this is usually in the URL - https://jenkins.domain.io/job/job-name-example/123 In this example URL the job name would be - job-name-example

Step 2

@thomaschaplin
thomaschaplin / get-jenkins-build-time.groovy
Last active November 16, 2021 14:05
Get the total build time of Jenkins jobs
def numberOfHoursBack = 7 * 24
def totalBuildTime =
Jenkins.instance.getItems(Job.class).collect {
job ->
job.getBuilds().byTimestamp(System.currentTimeMillis() - numberOfHoursBack * 60 * 60 * 1000, System.currentTimeMillis())
}
.flatten()
.collect {
build -> build.getDuration()
@thomaschaplin
thomaschaplin / index.ts
Created November 11, 2021 10:30
Pull Value Out Of Map
type itemMap<T> = {
[itemName: string]: T
}
type Environments = {
[x: string]: Environment
}
export enum Environment {
/* eslint-disable no-unused-vars */