Skip to content

Instantly share code, notes, and snippets.

@jimklimov
jimklimov / curler-simpleMove.groovy
Last active April 17, 2025 08:29
Mass-move Jenkins queue items
// requires Simple Queue Plugin : https://plugins.jenkins.io/simple-queue/
// run this in Jenkins console to generate shell code
// create a token in sysadmin account, save as e.g. `~/.sq` in a trusted workstation
// and in a shell session define JENKINS_URL="https://USERNAME:`cat ~/.sq`@SERVERNAME"
// then paste the result of script below (tweak "it" matcher to your needs)
def q = Jenkins.instance.queue
println "for ID in \\"
q.items.findAll { it.task.name.contains('2904') }.each { println it.id + " \\" }
println "; do ( curl -X POST \"\${JENKINS_URL}/simpleMove/move?moveType=DOWN_FAST&itemId=\${ID}\" || { sleep 120 ; curl -X POST \"\${JENKINS_URL}/simpleMove/move?moveType=DOWN_FAST&itemId=\${ID}\" ; } ) & done"
@jimklimov
jimklimov / network-start.sh
Created April 9, 2025 11:10
WSL2 Linux VM networking init
#!/bin/sh
# https://superuser.com/questions/1582234/make-ip-address-of-wsl2-static/1808525#1808525
# https://superuser.com/a/1723531/433945
# Add to /etc/wsl.conf as boot/command="/root/network-start.sh" for autostart
# (C) 2023-2025 by Jim Klimov (and other SO/GH/blog authors)
#
# This script assigns a fixed IP to the VM, fixes up DNS,
# allows fixed port on host for SSH dial-back into the VM
# and starts the SSH server.
@jimklimov
jimklimov / xmllint-jenkins-builds.sh
Created April 7, 2025 07:51
Parsing Jenkins build history for broken XML files with xmllint
# 1) Jenkins uses XML 1.1 standard that did not pick up in the industry after 20 years.
# So browsers and xmllint claim they do not know of it: https://stackoverflow.com/a/4508357
# Jenkins docs suggest replacing with "1.0" should suffice: https://www.jenkins.io/doc/upgrade-guide/2.107/
# 2) changelogNNNNNNNNNN.xml files are not XML but git commit info in fact
# 3) Some of those are plain empty and upset xmllint
# 4) xmllint insists on having an input file, so after rewrites we give it /dev/stdin.
# This path name may be a feature of bash and/or certain platforms.
find . -name '*.xml' | while read F ; do
[ -s "$F" ] || continue;
@jimklimov
jimklimov / gist:940742b4ed756e070095199e0335ca13
Created February 5, 2025 17:30
Exploratory Groovy to list GIT sources of MBP Jobs
Jenkins.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob).each { def project ->
//def flow = project.getDefinition()
//println "=== ${project.fullName}" // + " => ${flow} => ${flow.getDescriptor()}"
// + " - " + project.properties
def brProp = project.getProperty(org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty.class)
def br = brProp?.getBranch()
def brScm = br?.getScm()
//println " * ${brScm && brScm instanceof hudson.plugins.git.GitSCM ? brScm.getScmName() : brScm} => ${br?.getName()} => ${br?.getHead()} => ${br?.getSourceId()}"
if (brScm && brScm instanceof hudson.plugins.git.GitSCM) {
@jimklimov
jimklimov / README.md
Last active January 27, 2025 10:03
QEMU-GA on OmniOS and OpenIndiana
  • Install the qemu package which contains a .../bin/qemu-ga(OOCE Extra repo in case of OmniOS) among the server implementation
:; pkg install qemu

# On OmniOS also:
:; ln -s ../../opt/ooce/bin/qemu-ga /usr/bin
  • Edit config file; note that the method and path depend on hypervisor-provided device (virtio-agent or ISA -- without a dedicated driver package, only the latter
@jimklimov
jimklimov / jenkins-seed-job-CI-repo.groovy
Last active January 17, 2025 13:03
Quick and dirty Mother Seed Job for Jenkins pipelines
// Quick and dirty Mother Seed Job for Jenkins pipelines
// when many Jenkinsfiles live in same CI repository.
// Creates (if absent) a folder populated by multi-branch
// pipelines, each relying on its Git repo and pipeline
// filename (should be unique by naming construct below).
//
// NOTE: Needs "Job DSL plugin" installed
//
// NOTE: You will need to approve a number of method signatures
// at $JENKINS_URL/scriptApproval/ before it completes successfully.
@jimklimov
jimklimov / gist:a8dc06eacdf05eff7edc2bb69f42c0f2
Last active December 9, 2024 15:47
Jenkins SCM Changesets investigation
def b = Jenkins.instance.getItem("job-name").getBuildByNumber(1234)
println("Build name:\t${b}")
def mapCommitScm = [:]
b.getSCMs().each { scm ->
println("SCM:\t${scm}")
println("* Key:\t${scm.getKey()}")
println("* Branches:\t${scm.getBranches()}")
//println("* DN:\t${scm.getDisplayName()}")
//println("* URL:\t${scm.guessBrowser()?.repoUrl}")
@jimklimov
jimklimov / DependencyTrack-01-COMPONENTS_V.md
Last active September 25, 2024 11:37
Dependency-Track manually analyzed and/or depended-on components

PostgreSQL:

-- Helper view, indexes and methods

SET statement_timeout TO 0;

BEGIN;

-- Methods and their indices, to find UUID hits in DIRECT_DEPENDENCIES columns as text (JSON docs)

🛠 groovy scripts for jenkins credentials

... keeping update ...

@jimklimov
jimklimov / gist:4c489b7ccbd5ce89b293cea483b9f6fd
Created October 24, 2023 14:26
Jenkins - investigate job causes (e.g. to find SCM sources)
// Paste to your JENKINS_URL/script console:
def job = Jenkins.instance.getItemByFullName("org/repo/branch")
println "job: ${job}"
def build = job.getBuildByNumber(123)
println build
def commitHashForBuild(build) {
def scmAction = null