Skip to content

Instantly share code, notes, and snippets.

@firemanxbr
Created April 16, 2018 15:00
Show Gist options
  • Save firemanxbr/bf2429a5fab065802e8bfd4380fe2bfa to your computer and use it in GitHub Desktop.
Save firemanxbr/bf2429a5fab065802e8bfd4380fe2bfa to your computer and use it in GitHub Desktop.
node('maven') {
def productName = "rhproduct"
def url = "https://jenkins-rhproduct.192.168.42.242.nip.io"
def sa = "system:serviceaccount:${productName}:jenkins-admin".replaceAll(":", "_")
echo "${sa}"
sh 'wget https://gist.githubusercontent.com/scoheb/c960a534b592552d96265f03af52f4bf/raw/f74c5799e7c7a727ee1d42b2cfd06811ef283ac4/gistfile1.txt -O get-api-token.groovy'
sh 'curl -k --data-urlencode "script=$(< ./get-api-token.groovy)" -H "Authorization: Bearer `oc serviceaccounts get-token jenkins -n ' + productName + '`" ' + url + '/scriptText'
String apiToken = sh(
script: 'curl -k --data-urlencode "script=$(< ./get-api-token.groovy)" -H "Authorization: Bearer `oc serviceaccounts get-token jenkins -n ' + productName + '`" ' + url + '/scriptText | cut -c8-',
returnStdout: true
).trim()
echo apiToken
sh 'curl -k -H "Authorization: Bearer `oc serviceaccounts get-token jenkins -n ' + productName + '`" ' + url + '/job/test/build'
//sh "wget --no-check-certificate ${url}/jnlpJars/jenkins-cli.jar -O /tmp/jenkins-cli.jar"
//sh "java -jar /tmp/jenkins-cli.jar -auth ${sa}:${apiToken} -noCertificateCheck -s ${url} build test -w"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment