From cc5ba301274b7cf525399b99a77ddbda5995d9a2 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm <2292245+fwilhe@users.noreply.github.com> Date: Thu, 18 Apr 2019 10:00:29 +0200 Subject: [PATCH] Delete JenkinsController.groovy (#648) This file is moved to the dedicated testing repo and thus not required here anymore. --- .../piper/testutils/JenkinsController.groovy | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 src/com/sap/piper/testutils/JenkinsController.groovy diff --git a/src/com/sap/piper/testutils/JenkinsController.groovy b/src/com/sap/piper/testutils/JenkinsController.groovy deleted file mode 100644 index 1e4d0476d..000000000 --- a/src/com/sap/piper/testutils/JenkinsController.groovy +++ /dev/null @@ -1,122 +0,0 @@ -package com.sap.piper.jenkins - -import com.cloudbees.groovy.cps.NonCPS - -class JenkinsController implements Serializable { - def script - String jenkinsUrl - def timeout - - JenkinsController(script, String jenkinsUrl = "http://localhost:8080", timeout = 3600) { - this.script = script - this.jenkinsUrl = jenkinsUrl - this.timeout = timeout - } - - def waitForJenkinsStarted() { - def timeout = 120 - def timePerLoop = 5 - - for (int i = 0; i < timeout; i += timePerLoop) { - script.sleep timePerLoop - try { - if (retrieveJenkinsStatus() == 'NORMAL') { - return true - } - } catch (Exception e) { - script.echo "Could not retrieve status for Jenkins at ${jenkinsUrl}/api/json. Message: ${e.getMessage()}. Retrying..." - e.printStackTrace() - continue - } - return false - } - script.error("Timeout: Jenkins did not start within the expected time frame.") - } - - private retrieveJenkinsStatus() { - def apiUrl = "${jenkinsUrl}/api/json" - script.echo "Checking Jenkins Status" - def response = getTextFromUrl(apiUrl) - def result = script.readJSON text: response - return result.mode - } - - //Trigger scanning of the multi branch builds - def buildJob(String jobName) { - script.sh "curl -s -X POST ${jenkinsUrl}/job/${URLEncoder.encode(jobName, 'UTF-8')}/build" - } - - def waitForSuccess(String jobName, String branch) { - if (this.waitForJobStatus(jobName, branch, 'SUCCESS')) { - this.printConsoleText(jobName, branch) - script.echo "Build was successful" - } else { - this.printConsoleText(jobName, branch) - script.error("Build of ${jobName} ${branch} was not successfull") - } - } - - def getBuildUrl(String jobName, String branch) { - return "${jenkinsUrl}/job/${URLEncoder.encode(jobName, 'UTF-8')}/job/${URLEncoder.encode(branch, 'UTF-8')}/lastBuild/" - } - - def waitForJobStatus(String jobName, String branch, String status) { - def buildUrl = getBuildUrl(jobName, branch) - def timePerLoop = 10 - - for (int i = 0; i < timeout; i += timePerLoop) { - script.sleep timePerLoop - try { - script.echo "Checking Build Status of ${jobName} ${branch}" - def buildInformation = retrieveBuildInformation(jobName, branch) - - if (buildInformation.building) { - script.echo "Build is still in progress" - continue - } - if (buildInformation.result == status) { - return true - } - } catch (Exception e) { - script.echo "Could not retrieve status for ${buildUrl}. Message: ${e.getMessage()}. Retrying..." - continue - } - return false - } - script.error("Timeout: Build of job ${jobName}, branch ${branch} did not finish in the expected time frame.") - } - - def getConsoleText(String jobName, String branch) { - def consoleUrl = this.getBuildUrl(jobName, branch) + "/consoleText" - return getTextFromUrl(consoleUrl) - } - - def printConsoleText(String jobName, String branch) { - String consoleOutput = getConsoleText(jobName, branch) - - script.echo '***********************************************' - script.echo '** Begin Output of Example Application Build **' - script.echo '***********************************************' - - script.echo consoleOutput - - script.echo '*********************************************' - script.echo '** End Output of Example Application Build **' - script.echo '*********************************************' - } - - def retrieveBuildInformation(String jobName, String branch) { - def buildUrl = getBuildUrl(jobName, branch) - def url = "${buildUrl}/api/json" - script.echo "Checking Build Status of ${jobName} ${branch}" - script.echo "${jenkinsUrl}/job/${URLEncoder.encode(jobName, 'UTF-8')}/job/${URLEncoder.encode(branch, 'UTF-8')}/" - def response = getTextFromUrl(url) - def result = script.readJSON text: response - return result - } - - @NonCPS - private static String getTextFromUrl(url) { - return new URL(url).getText() - } -}