get secret text:
echo withCredentials([string(credentialsId: "<id>", variable: "s")]) { s }
get username and password:
println withCredentials([usernamePassword(credentialsId: "<id>", usernameVariable: "u", passwordVariable: "p")]) { [u, p] }
| COOKIE_JAR=/tmp/cookies | |
| CRUMB=$(curl -s --cookie-jar $COOKIE_JAR -u $JENKINS_USER:$JENKINS_TOKEN $JENKINS_URL/crumbIssuer/api/json | \ | |
| jq -r .crumb) | |
| curl -i --cookie $COOKIE_JAR -u $JENKINS_USER:$JENKINS_TOKEN \ | |
| -H "Jenkins-Crumb:${CRUMB}" -d "script=println 'foo'" \ | |
| $JENKINS_URL/scriptText \ |
get secret text:
echo withCredentials([string(credentialsId: "<id>", variable: "s")]) { s }
get username and password:
println withCredentials([usernamePassword(credentialsId: "<id>", usernameVariable: "u", passwordVariable: "p")]) { [u, p] }
| import org.junit.* | |
| import com.lesfurets.jenkins.unit.* | |
| import static groovy.test.GroovyAssert.* | |
| class ToAlphanumericTest extends BasePipelineTest { | |
| def toAlphanumeric | |
| @Before | |
| void setUp() { | |
| super.setUp() |
| import groovy.util.* | |
| import java.text.* | |
| def cli = new CliBuilder(usage: "ConvertLongTime [options] <time>") | |
| cli._(longOpt: "iso", "ISO format") | |
| def opts = cli.parse(args) | |
| if (!opts) { return } | |
| if (!opts.arguments()) { | |
| cli.usage() |
| // calculate hoursPerPoint based on velocity | |
| println "Base:" | |
| daysPerSprint = 10 | |
| println "daysPerSprint = $daysPerSprint" | |
| teamSize = 10 // not incl. ben, otis, adrian, support person | |
| println "teamSize = $teamSize" |
| class Time { | |
| static final INSTANT_PATTERN = | |
| ~/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z(|[\-\+]{1}[0-9]{4})?/ | |
| static timingEnabled = false | |
| static console = true | |
| private Time() {} | |
| static toGregorianCalendar(Instant instant) { | |
| instant ? GregorianCalendar.from(ZonedDateTime.ofInstant(instant, ZoneOffset.UTC)) : null |
| class RestClient { | |
| def proxy = Proxy.NO_PROXY | |
| def basicAuth | |
| // ???: Bake this into request()? | |
| static def encodePath(path) { | |
| path.replaceAll(" ", "%20") | |
| } | |
| def getContent(String url) { |
| import java.text.* | |
| class Dates { | |
| static final DATE_TIME = "yyyy-MM-dd HH:mm:ss" | |
| static final EUROPEAN = "dd/MM/yyyy" | |
| static final HSQLDB = "yyyy-MM-dd HH:mm:ss.SSS" | |
| static final ISO = "yyyy-MM-dd'T'HH:mm:ss.SSS" | |
| static final YEAR_MONTH_DAY = "yyyy-MM-dd" | |
| static final YEAR_MONTH_DAY_HOUR_MINUTE = "yyyy-MM-dd (HH:mm)" | |
| static final MONTH_DAY_YEAR = "MM/dd/yyyy" |
| class CsvDoc { | |
| def doc = [] | |
| def setHeader(titles) { | |
| doc = [ toCsv(titles) ] + doc | |
| } | |
| def addRow(values) { | |
| doc << toCsv(values) | |
| } |
| import java.io.*; | |
| import java.net.*; | |
| import java.util.*; | |
| import java.text.*; | |
| /** | |
| * SmtpMailer is used to send mail using SMTP. | |
| * | |
| * @author Thornton Rose | |
| * @version 1.0 |