Skip to content

Instantly share code, notes, and snippets.

View steven-terrana's full-sized avatar
🚀

Steven Terrana steven-terrana

🚀
View GitHub Profile
@steven-terrana
steven-terrana / initialize_multibranch.groovy
Last active September 10, 2019 14:04
[Jenkins Seed Multibranch Jobs] initialize multibranch projects with the first sha #Jenkins
import org.boozallen.plugins.jte.config.*;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
import org.jenkinsci.plugins.github_branch_source.GitHubSCMSource;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.BranchSpec;
import hudson.plugins.git.UserRemoteConfig;
import jenkins.branch.BranchSource;
import org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait;
import org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait;
import jenkins.scm.api.trait.SCMSourceTrait;
@steven-terrana
steven-terrana / getPlugins.groovy
Created September 10, 2019 15:06
[Get plugins.txt] get all installed plugins and their versions in the required plugins.txt format #Jenkins
def plugins = [:]
Jenkins.instance.pluginManager.plugins.each{ plugin ->
plugins[plugin.getShortName()] = plugin.getVersion()
}
plugins.keySet().sort().each{ shortName ->
println "${shortName}:${plugins.getAt(shortName)}"
}
@steven-terrana
steven-terrana / kill_all.groovy
Created September 10, 2019 17:48
[Kill All Builds] kill all queued and running jobs #Jenkins
import java.util.ArrayList
import hudson.model.*;
// Remove everything which is currently queued
def q = Jenkins.instance.queue
for (queued in Jenkins.instance.queue.items) {
q.cancel(queued.task)
}
// stop all the currently running jobs
@steven-terrana
steven-terrana / prettyPrint.groovy
Created September 12, 2019 20:29
[Pretty Print Groovy Map] #groovy
import static groovy.json.JsonOutput.*
def config = [
/*
some map
*/
]
println prettyPrint(toJson(config))
@steven-terrana
steven-terrana / example.groovy
Last active May 10, 2023 15:16
Convert YAML to ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter
import org.jenkinsci.plugins.pipeline.modeldefinition.parser.JSONParser
import net.sf.json.JSONObject
import org.yaml.snakeyaml.Yaml
import com.github.fge.jsonschema.tree.JsonTree
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef
String yamlString = """
pipeline:
stages:
@steven-terrana
steven-terrana / create-kubeconfig.sh
Last active February 16, 2021 00:59
Create KubeConfig
# from: https://stackoverflow.com/a/47776588
# which service account?
SA=
NAMESPACE=
# your k8s api endpoint goes here
server=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
# the name of the secret containing the service account token goes here
variable "field_A" {
type = string
default = "default value A"
}
output "field_A" {
value = var.field_A
}
variable "field_B" {
@steven-terrana
steven-terrana / application.yaml
Created September 30, 2020 17:06
use outputs from co-created resources with kubernetes-alpha provider
apiVersion: v1
kind: ConfigMap
metadata:
name: test-config-${int}
namespace: default
data:
something: "value"
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: jenkins-agent
name: jenkins-agent
namespace: demo
spec:
replicas: 2
selector:
import example.GitServerProvider
ExtensionPoint.lookup(GitServerProvider).each{ s ->
def provider = s.newInstance()
provider.doThingOne()
provider.doThingTwo()
}