Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
| #!/bin/bash | |
| # Author Ryan Kulla ([email protected]) | |
| # | |
| # A shell script (in Bash) that allows you to do SVN checkouts | |
| # with a shorter command than the default subversion command. | |
| # Handy if your repos have long, hard to remember URLs. | |
| # | |
| # Put this script in your PATH (e.g., ~/bin/) | |
| # Make sure it's executable: | |
| # $ chmod u+x ~/bin/co |
| /*** BEGIN META { | |
| "name": "List GIT Branches", | |
| "comment": "You can use this to fill up a dynamic list parameter with branches. Optionally, you can filter the branches to show.", | |
| "parameters": [ 'FILTER', 'REMOTE' ], | |
| "core": "1.580", | |
| "authors": [ | |
| { name : "Jan Vansteenkiste" } | |
| ] | |
| } END META**/ |
| # Script Name: powerssh | |
| # Version: 1.1.0 (9. July, 2014) | |
| # Author: Sveinn Steinarsson | |
| # Description: Use Powershell to connect to a remote server via SSH and run a shell script/command | |
| # Prerequisite: | |
| # plink.exe in script path (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) | |
| # Examples: | |
| # With key file (*.ppk) and script file |
| rem | |
| rem Please download curl from https://curl.haxx.se/download.html and add it to your path. | |
| rem | |
| @echo on | |
| rem if command fails, exit and do not ping | |
| if %errorlevel% neq 0 goto ERROR | |
| set URL_STRING=http://pshmn.com/eaFnY | |
| curl %URL_STRING% |
| def cmd = 'hostname' | |
| def sout = new StringBuffer(), serr = new StringBuffer() | |
| def proc = cmd.execute() | |
| proc.consumeProcessOutput(sout, serr) | |
| proc.waitForOrKill(1000) | |
| println sout |
Simple collection of Groovy scripts to help me maintain some Jenkins systems.
See also https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
| import jenkins.model.Jenkins; | |
| import hudson.model.FreeStyleProject; | |
| import hudson.tasks.Shell; | |
| job = Jenkins.instance.createProject(FreeStyleProject, 'job-name') | |
| job.buildersList.add(new Shell('echo hello world')) | |
| job.save() |
| import com.cloudbees.plugins.credentials.* | |
| import com.cloudbees.plugins.credentials.common.* | |
| import com.cloudbees.plugins.credentials.domains.* | |
| def credentials_for_username(String username) { | |
| def username_matcher = CredentialsMatchers.withUsername(username) | |
| def available_credentials = | |
| CredentialsProvider.lookupCredentials( | |
| StandardUsernameCredentials.class, | |
| Jenkins.getInstance(), |
| // A Declarative Pipeline is defined within a 'pipeline' block. | |
| pipeline { | |
| // agent defines where the pipeline will run. | |
| agent { | |
| // This also could have been 'agent any' - that has the same meaning. | |
| label "" | |
| // Other possible built-in agent types are 'agent none', for not running the | |
| // top-level on any agent (which results in you needing to specify agents on | |
| // each stage and do explicit checkouts of scm in those stages), 'docker', |