| |
@@ -0,0 +1,43 @@
|
| |
+ steps {
|
| |
+ script {
|
| |
+ echo "Curl ${params.TOWER_INSTANCE}/api/v2/job_templates/${params.TOWER_TEMPLATE_ID}/launch/"
|
| |
+ openshift.withCluster() {
|
| |
+ if ( openshift.selector('secret', params.TOWER_SECRET).exists() ) {
|
| |
+ def towerSecretData = openshift.selector('secret', params.TOWER_SECRET).object().data
|
| |
+ if ( !towerSecretData.containsKey("USERNAME") || !towerSecretData.containsKey("PASSWORD") ) {
|
| |
+ error("There is not USERNAME or PASSWORD in ${params.TOWER_SECRET}")
|
| |
+ }
|
| |
+ def towerUser = new String(towerSecretData.USERNAME.decodeBase64())
|
| |
+ def towerPassword = new String(towerSecretData.PASSWORD.decodeBase64())
|
| |
+
|
| |
+ def launchUrl = "${params.TOWER_INSTANCE}/api/v2/job_templates/${params.TOWER_TEMPLATE_ID}/launch/"
|
| |
+ echo "curl -X POST -u ${towerUser}:***** ${launchUrl}"
|
| |
+ def launchOut = sh script: "set +x; curl -k -X POST -u ${towerUser}:${towerPassword} ${launchUrl}", returnStdout: true
|
| |
+ def launchOutJson
|
| |
+ try {
|
| |
+ launchOutJson = readJSON text: launchOut
|
| |
+ } catch (Exception e) {
|
| |
+ error("Unable parse output: ${launchOut}")
|
| |
+ }
|
| |
+ if (!launchOutJson.containsKey("created")){
|
| |
+ error("Job was not created from template: ${launchOut}")
|
| |
+ }
|
| |
+ def finished = launchOutJson.finished
|
| |
+ def jobUrl = "${params.TOWER_INSTANCE}${launchOutJson.url}"
|
| |
+ def jobOutJson
|
| |
+ while(finished == "null"){
|
| |
+ sh "set +x; sleep 5; echo 'checking state of ${launchOutJson.id} job'"
|
| |
+ def jobOut = sh script: "set +x; curl -k -u ${towerUser}:${towerPassword} ${jobUrl}", returnStdout: true
|
| |
+ jobOutJson = readJSON text: jobOut
|
| |
+ finished = jobOutJson.finished
|
| |
+ }
|
| |
+ if (jobOutJson.failed) {
|
| |
+ error("Tower job ${params.TOWER_INSTANCE}/#/jobs/playbook/${jobOutJson.id} execution failed")
|
| |
+ }
|
| |
+ echo "Job ${params.TOWER_INSTANCE}/#/jobs/playbook/${jobOutJson.id} execution passed"
|
| |
+ } else {
|
| |
+ error("Secret ${params.TOWER_SECRET} doesn't exist")
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |