Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Please comment & let me know if you have a fork / fixes you'd like to include.
| DemoHandler | |
| --- | |
| def lambda_handler(event, context): | |
| print(event) | |
| return "hello, world!!" | |
| DemoAuthorizer | |
| --- |
| # Get ExternalIPs of all nodes | |
| kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}' | |
| # List Names of Pods that belong to Particular RC | |
| # "jq" command useful for transformations that are too complex for jsonpath, it can be found at https://stedolan.github.io/jq/ | |
| sel=${$(kubectl get rc my-rc --output=json | jq -j '.spec.selector | to_entries | .[] | "\(.key)=\(.value),"')%?} | |
| echo $(kubectl get pods --selector=$sel --output=jsonpath={.items..metadata.name}) | |
| # Check which nodes are ready | |
| JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \ | |
| && kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True" | |
| # List all Secrets currently in use by a pod |
| #!groovy | |
| // imports | |
| import com.cloudbees.jenkins.plugins.sshcredentials.impl.* | |
| import com.cloudbees.plugins.credentials.* | |
| import com.cloudbees.plugins.credentials.common.* | |
| import com.cloudbees.plugins.credentials.domains.Domain | |
| import com.cloudbees.plugins.credentials.impl.* | |
| import hudson.util.Secret | |
| import java.nio.file.Files |
| #!groovy | |
| // imports | |
| import com.cloudbees.plugins.credentials.* | |
| import com.cloudbees.plugins.credentials.domains.Domain | |
| import com.cloudbees.plugins.credentials.impl.* | |
| import hudson.util.Secret | |
| import jenkins.model.Jenkins | |
| // parameters |
| # delete local tag '12345' | |
| git tag -d 12345 | |
| # delete remote tag '12345' (eg, GitHub version too) | |
| git push origin :refs/tags/12345 | |
| # alternative approach | |
| git push --delete origin tagName | |
| git tag -d tagName |
| #other way is to use bitbucket api call | |
| #create a personal access token from bitbucket app passwords and use it here, and give the name of the tag and target hash | |
| curl -X POST -u username:Passwd -H "Content-Type: application/json" -v --trace - -d '{"name":"nameoftag","target":{"hash":"gitcommitid_whichyouwanttotag"}}' \ | |
| https://api.bitbucket.org/2.0/repositories/yourname/yourreponame/refs/tags |
| kubectl delete "$(kubectl api-resources --namespaced=true --verbs=delete -o name | tr "\n" "," | sed -e 's/,$//')" --all |
| #!/bin/bash | |
| aws ecr describe-repositories | jq '.repositories[].repositoryName' | xargs -I {} aws ecr put-lifecycle-policy --repository-name {} --lifecycle-policy-text "file://policy.json" | |
| ///////////////////////// | |
| #the other way is to store it in some varible and pass it in the cmd line | |
| #here am giving major lifecycle policies like | |
| # 1) removing untagged images | |
| # 2) storing only images with specific tag prefix |
| #!/usr/bin/env bash | |
| # Example: | |
| # ./find-ecr-image.sh foo/bar mytag | |
| if [ $# -lt 2 ]; then | |
| echo "Usage: $( basename $0 ) <repository-name> <image-tag>" | |
| exit 1 | |
| fi | |
| IMAGE_META="$( aws ecr describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )" |
Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
Please comment & let me know if you have a fork / fixes you'd like to include.