Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / jenkins-approve-script.groory
Created June 3, 2020 06:13
jenkins-approve-script.groory
import java.lang.reflect.*;
import jenkins.model.Jenkins;
import jenkins.model.*;
import org.jenkinsci.plugins.scriptsecurity.scripts.*;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.*;
scriptApproval = ScriptApproval.get()
alreadyApproved = new HashSet<>(Arrays.asList(scriptApproval.getApprovedSignatures()))
@gwsu2008
gwsu2008 / pipeline-get-userId.groovy
Created May 28, 2020 21:47
pipeline-get-userId.groovy
#NonCPS
def getBuildUser() {
return currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()
}
@NonCPS
def getBuildUserName() {
return currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserName()
}
@gwsu2008
gwsu2008 / maven-local-repo
Last active May 26, 2020 05:00
maven-local-repo
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository -->
<localRepository>E:/devsetup/M2</localRepository>
@gwsu2008
gwsu2008 / jenkins-groovy-print-all-jobs.groovy
Created May 23, 2020 19:32
jenkins-groovy-print-all-jobs.groovy
Jenkins.instance.getAllItems(Job.class).each{
println it.name + " - " + it.class + '\n'
}
@gwsu2008
gwsu2008 / jenkins-groovy-print-all-jobs.groovy
Created May 23, 2020 19:32
jenkins-groovy-print-all-jobs.groovy
Jenkins.instance.getAllItems(Job.class).each{
println it.name + " - " + it.class + '\n'
}
@gwsu2008
gwsu2008 / jenkins-groovy-get-nodes.groovy
Created May 21, 2020 23:21
jenkins-groovy-get-nodes.groovy
import hudson.FilePath
import hudson.model.Node
import hudson.model.Slave
import jenkins.model.Jenkins
Jenkins jenkins = Jenkins.instance
for (Node node in jenkins.nodes) {
// Make sure slave is online
if (!node.toComputer().online) {
println "Node '$node.nodeName' is currently offline - skipping workspace cleanup"
@gwsu2008
gwsu2008 / jenkins-get-plugins.groovy
Last active April 5, 2021 18:04
jenkins-get-plugins.groovy
Jenkins.instance.pluginManager.plugins.each{
plugin ->
println ("${plugin.getDisplayName()} | ${plugin.getShortName()} : ${plugin.getVersion()}")
}
@gwsu2008
gwsu2008 / CustomResources
Created May 13, 2020 16:52
AWS Cloudformation Custom Resources
MyCustomResource:
DependsOn: SnsTopic
Type: "Custom::TestLambdaCrossStackRef"
Properties:
ServiceToken: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:myTestLambda"
StackName: !Ref "AWS::StackName"
SnsTopicArn: !Ref SnsTopic
SuccessRoleArn: !GetAtt "SnSSuccessfulRole.Arn"
FailureRoleArn: !GetAtt "SnSFailedRole.Arn"
@gwsu2008
gwsu2008 / aws-kms-key-share-policy
Created May 7, 2020 05:09
aws-kms-key-share-policy
{
"Version": "2012-10-17",
"Id": "key-consolepolicy-3",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::1234567890:root"
},
@gwsu2008
gwsu2008 / remove-offline-nodes.groovy
Created May 6, 2020 21:19
remove-offline-nodes.groovy
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.getComputer().isOffline()) {
aSlave.getComputer().setTemporarilyOffline(true,null);
aSlave.getComputer().doDoDelete();
}
}