From fa4c1a1631dce4cdb651f4e206d92e8069433714 Mon Sep 17 00:00:00 2001 From: jdewinne Date: Wed, 11 May 2016 16:38:14 -0700 Subject: [PATCH] Defined types: --- .gitignore | 3 + src/main/resources/CapOne/JenkinsBuild.py | 151 ------------------ .../{jenkins => ipsw}/EnvInjectBuild.py | 8 +- src/main/resources/synthetic.xml | 19 +-- 4 files changed, 14 insertions(+), 167 deletions(-) create mode 100644 .gitignore delete mode 100644 src/main/resources/CapOne/JenkinsBuild.py rename src/main/resources/{jenkins => ipsw}/EnvInjectBuild.py (93%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0d53d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.gradle +.idea +build diff --git a/src/main/resources/CapOne/JenkinsBuild.py b/src/main/resources/CapOne/JenkinsBuild.py deleted file mode 100644 index 54c95a6..0000000 --- a/src/main/resources/CapOne/JenkinsBuild.py +++ /dev/null @@ -1,151 +0,0 @@ -# -# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS -# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS. -# - -import sys, time, urllib -from com.xebialabs.xlrelease.plugin.webhook import JsonPathResult - -""" -Calls Jenkins API in order to know if a job expect parameters -When expecting a parameter named "param", the JSON looks like: - - "actions" : [ - { - "parameterDefinitions" : [ - { - "defaultParameterValue" : { - "name" : "param", - "value" : "" - }, - "description" : "", - "name" : "param", - "type" : "StringParameterDefinition" - } - ] - } - ] -""" -def isJobParameterized(request, jobContext): - jobInfo = request.get(jobContext + 'api/json', contentType = 'application/json') - jobActions = JsonPathResult(jobInfo.response, 'actions').get() - - if jobActions is not None: - for action in jobActions: - if (action is not None and 'parameterDefinitions' in action): - return True - - return False - -""" -With an input that looks like: -param1=value 1\n -param2=value 2\n - -Produces: ?param1=value%201¶m2=value%202 to be used as a query string -""" -def buildQueryString(params): - if (params is not None): - queryParams = [] - for param in params.splitlines(): - if param: - tokens = param.split('=', 1) - queryParams.append(tokens[0] + "=" + urllib.quote(tokens[1])) - return "?" + "&".join(queryParams) - else: - return "" - -""" -Print a nicely formatted build started message -""" -def notifyBuildStarted(jenkinsURL, jobContext, jobName, buildNumber): - jenkinsJobURL = jenkinsURL + jobContext + str(buildNumber) - print "Started [%s #%s](%s) - view [Console Output](%s)" % (jobName, buildNumber, jenkinsJobURL, jenkinsJobURL + '/console') - -""" -Sets the build number and status to the task output properties even if task failed -""" -def setOutputProperties(buildNumber, buildStatus): - task.pythonScript.setProperty('buildNumber', buildNumber) - task.pythonScript.setProperty('buildStatus', buildStatus) - from com.xebialabs.xlrelease.api import XLReleaseServiceHolder - XLReleaseServiceHolder.getRepositoryService().update(task.pythonScript) - - -poll_interval = jenkinsServer['pollInterval'] - -if jenkinsServer is None: - print "No server provided." - sys.exit(1) - -jenkinsURL = jenkinsServer['url'] - -jobUrl = jenkinsURL -jobContext = '/job/' + urllib.quote(jobName) + '/' - -request = HttpRequest(jenkinsServer, username, password) - -if isJobParameterized(request, jobContext): - buildContext = jobContext + 'buildWithParameters' + buildQueryString(jobParameters) -else: - buildContext = jobContext + 'build' - -buildUrl = jobUrl + buildContext - -buildResponse = request.post(buildContext, '', contentType = 'application/json') - -if buildResponse.isSuccessful(): - # query the location header which gives a queue item position (more reliable for retrieving the correct job later) - - # if 'Location' in buildResponse.getHeaders(): - location = None - if 'Location' in buildResponse.getHeaders() and '/queue/item/' in buildResponse.getHeaders()['Location']: - location = '/queue/item/' + filter(None, buildResponse.getHeaders()['Location'].split('/'))[-1] + '/' - - # polls until the job has been actually triggered (it could have been queued) - while True: - time.sleep(poll_interval) - - # fallback to the unreliable check because old jenkins(<1.561) does not populate the Location header - if location: - # check the response to make sure we have an item - response = request.get(location + 'api/json', contentType = 'application/json') - if response.isSuccessful(): - # if we have been given a build number this item is no longer in the queue but is being built - buildNumber = JsonPathResult(response.response, 'executable.number').get() - if buildNumber: - notifyBuildStarted(jenkinsURL, jobContext, jobName, buildNumber) - break - else: - print "Could not determine build number for queued build at %s." % (jenkinsURL + location + 'api/json') - sys.exit(1) - else: - response = request.get(jobContext + 'api/json', contentType = 'application/json') - # response.inQueue is a boolean set to True if a job has been queued - inQueue = JsonPathResult(response.response, 'inQueue').get() - if not inQueue: - buildNumber = JsonPathResult(response.response, 'lastBuild.number').get() - notifyBuildStarted(jenkinsURL, jobContext, jobName, buildNumber) - break - - # polls until the job completes - while True: - # now we can track our builds - time.sleep(poll_interval) - response = request.get(jobContext + str(buildNumber) + '/api/json', contentType = 'application/json') - buildStatus = JsonPathResult(response.response, 'result').get() - duration = JsonPathResult(response.response, 'duration').get() - if buildStatus and duration != 0: - break - - print "\nFinished: %s" % buildStatus - if buildStatus == 'SUCCESS': - sys.exit(0) - else: - setOutputProperties(buildNumber, buildStatus) - sys.exit(1) -else: - print "Failed to connect at %s." % buildUrl - buildResponse.errorDump() - sys.exit(1) \ No newline at end of file diff --git a/src/main/resources/jenkins/EnvInjectBuild.py b/src/main/resources/ipsw/EnvInjectBuild.py similarity index 93% rename from src/main/resources/jenkins/EnvInjectBuild.py rename to src/main/resources/ipsw/EnvInjectBuild.py index ff50710..9ea2cdf 100644 --- a/src/main/resources/jenkins/EnvInjectBuild.py +++ b/src/main/resources/ipsw/EnvInjectBuild.py @@ -30,7 +30,7 @@ def isJobParameterized(request, jobContext): jobInfo = request.get(jobContext + 'api/json', contentType = 'application/json') if not jobInfo.isSuccessful: - print "Failed to get response from jenkins, received [%s] with content [%s]" % (jobInfo.status, jobInfo.response) + print "Failed to get response from ipsw, received [%s] with content [%s]" % (jobInfo.status, jobInfo.response) sys.exit(1) jobActions = JsonPathResult(jobInfo.response, 'actions').get() @@ -117,7 +117,7 @@ def build_env_vars(environment_vars): while True: time.sleep(poll_interval) - # fallback to the unreliable check because old jenkins(<1.561) does not populate the Location header + # fallback to the unreliable check because old ipsw(<1.561) does not populate the Location header if location: found_build_number = False for x in range(build_number_retrial_count): @@ -133,7 +133,7 @@ def build_env_vars(environment_vars): else: time.sleep(poll_interval) else: - print "Failed to get response from jenkins, received [%s] with content [%s]" % (response.status, response.response) + print "Failed to get response from ipsw, received [%s] with content [%s]" % (response.status, response.response) time.sleep(poll_interval) if found_build_number: @@ -156,7 +156,7 @@ def build_env_vars(environment_vars): time.sleep(poll_interval) response = request.get(jobContext + str(buildNumber) + '/api/json', contentType = 'application/json') if not response.isSuccessful: - print "Failed to get response from jenkins, received [%s] with content [%s]" % (response.status, response.response) + print "Failed to get response from ipsw, received [%s] with content [%s]" % (response.status, response.response) continue buildStatus = JsonPathResult(response.response, 'result').get() duration = JsonPathResult(response.response, 'duration').get() diff --git a/src/main/resources/synthetic.xml b/src/main/resources/synthetic.xml index c026cc2..63dfcbf 100644 --- a/src/main/resources/synthetic.xml +++ b/src/main/resources/synthetic.xml @@ -8,20 +8,15 @@ --> - - - - + + \ No newline at end of file