Last active
November 8, 2023 08:02
-
-
Save foreignmeloman/167a409ee22a812749101c24ec34f994 to your computer and use it in GitHub Desktop.
Jenkins administrative snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList | |
| import hudson.model.*; | |
| import jenkins.model.Jenkins | |
| // 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 | |
| for (job in Jenkins.instance.items) { | |
| stopJobs(job) | |
| } | |
| def stopJobs(job) { | |
| if (job in com.cloudbees.hudson.plugins.folder.Folder) { | |
| for (child in job.items) { | |
| stopJobs(child) | |
| } | |
| } else if (job in org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) { | |
| for (child in job.items) { | |
| stopJobs(child) | |
| } | |
| } else if (job in org.jenkinsci.plugins.workflow.job.WorkflowJob) { | |
| if (job.isBuilding()) { | |
| for (build in job.builds) { | |
| build.doKill() | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | |
| com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, | |
| Jenkins.instance, | |
| null, | |
| null | |
| ); | |
| for (c in creds) { | |
| println( ( c.properties.privateKeySource ? "ID: " + c.id + ", UserName: " + c.username + ", Private Key: " + c.getPrivateKey() : "")) | |
| } | |
| for (c in creds) { | |
| println( ( c.properties.password ? "ID: " + c.id + ", UserName: " + c.username + ", Password: " + c.password : "")) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment