Skip to content

Instantly share code, notes, and snippets.

@pere3
pere3 / buildtime.groovy
Created October 9, 2020 12:10
Groovy script that find long running Jenkins jobs, and POST hook to saltstack reactor.
import groovy.json.JsonOutput
def runningBuilds = Jenkins.instance.getView('All').getBuilds().findAll() { it.isInProgress() }
LinkedHashMap notificationPayload = [:]
runningBuilds.each{ value ->
String jobName = value.getFullDisplayName()
int durationInSeconds = (System.currentTimeMillis() - value.getStartTimeInMillis())/1000
if (durationInSeconds > 3600) {
println("Job: ${jobName}, running for more than 1 hour long")
println("Running time: " + durationInSeconds)
@pere3
pere3 / DockerCleaner.groovy
Last active December 18, 2020 07:42
jenkins shared-library dangled images cleaner / images untag, can be used with gcr.io and other docker-compatible registries
class DockerCleaner {
DockerRegistry dockerRegistry
DockerCleaner(DockerRegistry dockerRegistry) {
this.dockerRegistry = dockerRegistry
}
ArrayList getImageDangledManifests(String imageName) {
def imageTags = dockerRegistry.getImageTags(imageName)
return imageTags.manifest.findAll {
@pere3
pere3 / build-stages-status.groovy
Created April 27, 2020 14:28 — forked from GuillaumeSmaha/build-stages-status.groovy
Functions to get stages executed and build state
import hudson.model.Action
import com.cloudbees.workflow.flownode.FlowNodeUtil
import com.cloudbees.workflow.rest.external.StatusExt
import org.jenkinsci.plugins.workflow.graph.FlowNode
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode
import org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode
import org.jenkinsci.plugins.workflow.actions.LabelAction
@pere3
pere3 / proxmox.py
Last active July 26, 2019 12:48
saltstack custom runner, proxmox themed, lvm-thin overprovisioning check
# -*- coding: utf-8 -*-
'''
Proxmox runner
'''
import json
import salt.utils.event
import salt.client
def lvm_check():
@pere3
pere3 / complex_salt_orchestrate.sls
Created December 25, 2018 11:56 — forked from whiteinge/complex_salt_orchestrate.sls
An example of a complex, multi-host Salt Orchestrate state that performs status checks as it goes
# /srv/salt/upgrade_the_app.sls
# Example of a complex, multi-host Orchestration state that performs status checks as it goes.
# Note, this is untested and is meant to serve as an example.
# Run via: salt-run state.orch upgrade_the_app pillar='{nodes: [nodeA, nodeB], version: 123}'
{% set nodes = salt.pillar.get('nodes', []) %}
{% set all_grains = salt.saltutil.runner('cache.grains',
tgt=','.join(nodes), tgt_type='list') %}
{# Default version if not given at the CLI. #}