Skip to content

Instantly share code, notes, and snippets.

View lewars's full-sized avatar

Alistair Y. Lewars lewars

  • New Jersey
  • 04:38 (UTC -04:00)
View GitHub Profile
pipeline {
agent any
stages {
stage('Hello') {
steps {
script {
docker.image("bitnami/kubectl:latest").inside("--userns=host --entrypoint=") {
sh 'kubectl config view'
}
# Test docker config is setup after running entrypoint.sh
@test "check docker config file is present" {
config=$(docker run --rm $image /bin/sh -c '/bin/ls -1 /root/.docker/config.json | grep config.json')
if [[ ! -z "$config" ]]then
return 0
fi
return 1
}
import jenkins.model.Jenkins
import hudson.model.ListView
def jenkins = Jenkins.getInstance()
def view = jenkins.getView("My View")
def jobs = view.getItems()
jobs.each { job ->
view.renameJob(job, "New Job Name")
view.getColumn("Job Name").setCell(job, "New Job Name")
@lewars
lewars / generate_csv_of_jenkins_jobs.groovy
Last active October 12, 2024 05:55
Groovy code to generate a csv of jobs
import jenkins.model.Jenkins
import hudson.model.*
Jenkins jenkins = Jenkins.getInstance()
def allJobs = jenkins.getAllItems()
def cmsJobs = allJobs.findAll { job -> job.name.contains("cms") }
println "Job Name| Disabled| Last Build Time"
cmsJobs.each { job ->
import jenkins.model.*
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import hudson.plugins.git.GitSCM
def gitUrl = 'https://github.com/foo/bar.git'
def jenkins = Jenkins.getInstance()
def pipelineJobs = jenkins.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob.class)
import os
import requests
import json
# Set the GitLab API token and URL
GITLAB_API_TOKEN = 'YOUR_GITLAB_API_TOKEN'
GITLAB_API_URL = 'https://gitlab.com/api/v4'
# Get the absolute path of the cloned repository
repo_path = os.path.abspath('/path/to/cloned/repo')
import tarfile
import gzip
import os
def tar_gzip_directory(directory_path, output_path):
"""
Creates a GZIP-compressed TAR archive of the specified directory.
:param directory_path: The path to the directory to be archived.
:param output_path: The path to the output file to be created.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: git
image: alpine/git:2.36.3
command:
- sh
import requests
import os
# Set the GitLab API endpoint and the registry project ID
api_endpoint = "https://gitlab.com/api/v4"
registry_project_id = "my-registry-project-id"
# Set the GitLab access token (must have read access to the registry project)
access_token = os.environ.get("GITLAB_ACCESS_TOKEN")
import os
import subprocess
# Set environment variables
os.environ["CI_JOB_TOKEN"] = "YOUR_CI_JOB_TOKEN"
# Define the GitLab Terraform module registry host and module path
registry_host = "https://gitlab.com"
module_namespace = "your-namespace"
module_name = "your-module"