Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Error 500 when using RESTful to update build #3415

maxfptv ·
Hi,
I want to determine if a build of a specific configuration actually did any work. I thought the easiest way to accomplish this would be adding a build variable with an initial value of 0. Now each step would increment the variable if it did anything.
I need to modify that build variable directly from within a script that is called by a Shell/Batch Command step, as I don't want to misuse the script's return code.
Therefore, I tried updating the build using the RESTful API (section Update build). Unfortunately this didn't work, the server replied with HTTP status 500.

I then wrote a simple script to test the functionality. All it does is retrieving XML representation of the build using the http GET method as suggested in the wiki and then posting it unmodified to
http://<server>/rest/build

The first part, getting the XML representation works fine, but updating the build didn't work either. Am I missing something here?

Additional information:
Authorization is done as admin user by adding a Authorization Basic header to the request.
I have tried using the RESTful API with my python2 script as well as curl but neither of it worked.
I have also tried different builds, including an old one and the currently running one.
QuickBuild version: 6.0.27

Also, if there is an easier method to do the whole thing, please let me know <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->

Thank you
Maximilian

testScript.py:

"""Test script for QuickBuild RESTful API"""
import sys, urllib2
from argparse import ArgumentParser

def encodeUserCredentials(username, password):
"""Encode user credentials for HTTP Authorization header"""
return (username + ':' + password).encode('base64').rstrip()

def parseArgs():
"""Parse the command line arguments"""
parser = ArgumentParser(description=__doc__)
parser.add_argument('-b', '--buildId', type=int, required=True)
parser.add_argument('-u', '--user', required=True)
parser.add_argument('-p', '--pass', required=True)
parser.add_argument('-s', '--server', required=True)
parser.add_argument('-P', '--port', type=int, required=True)

arguments = parser.parse_args()
return vars(arguments)

def main():
"""Main function"""
args = parseArgs()

# GET the build
request = urllib2.Request('http://%s:%d/rest/builds/%d' % (args['server'], args['port'], args['buildId']))
request.add_header('Accept', 'application/xml')
request.add_header('Authorization', 'Basic ' + encodeUserCredentials(args['user'], args['pass']))

try:
result = urllib2.urlopen(request)
except Exception as e:
print str(e)
sys.exit(1)

xmlString = result.read()

# POST the build
request = urllib2.Request('http://%s:%d/rest/build/' % (args['server'], args['port']), data=xmlString)
request.add_header('Authorization', 'Basic ' + encodeUserCredentials(args['user'], args['pass']))
request.add_header('Content-Type', 'application/xml')

result = None
try:
result = urllib2.urlopen(request)
except Exception as e:
print str(e)
sys.exit(2)

if result.code == 200:
sys.exit(0)


if __name__ == '__main__':
main()


Server log:

jvm 1 | 2016-01-14 17:08:14,342 INFO - Processing build request (configuration:root/Test/Test RESTful API, request id:***)
jvm 1 | 2016-01-14 17:08:14,352 INFO - Checking build condition on node (address: ***:8810, ip: ***)...
jvm 1 | 2016-01-14 17:08:14,354 INFO - Taking repository snapshots...
jvm 1 | 2016-01-14 17:08:14,369 INFO - New build version is calculated as '2016-01-14 17:08'.
jvm 1 | 2016-01-14 17:08:14,743 ERROR - Error serving restful request.
jvm 1 | com.sun.jersey.api.NotFoundException
jvm 1 | at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:991)
jvm 1 | at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
jvm 1 | at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
jvm 1 | at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
jvm 1 | at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
jvm 1 | at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
jvm 1 | at com.pmease.quickbuild.rest.RestServlet.service(RestServlet.java:48)
jvm 1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
jvm 1 | at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
jvm 1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
jvm 1 | at com.pmease.quickbuild.Quickbuild$DisableTraceFilter.doFilter(Quickbuild.java:1060)
jvm 1 | at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
jvm 1 | at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
jvm 1 | at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)
jvm 1 | at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
jvm 1 | at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
jvm 1 | at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
jvm 1 | at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
jvm 1 | at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
jvm 1 | at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
jvm 1 | at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
jvm 1 | at org.eclipse.jetty.server.Server.handle(Server.java:365)
jvm 1 | at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
jvm 1 | at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
jvm 1 | at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
jvm 1 | at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
jvm 1 | at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
jvm 1 | at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
jvm 1 | at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
jvm 1 | at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
jvm 1 | at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
jvm 1 | at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
jvm 1 | at java.lang.Thread.run(Unknown Source)
jvm 1 | 2016-01-14 17:08:15,097 INFO - Populating configuration data...
jvm 1 | 2016-01-14 17:08:15,098 INFO - Sending build notifications...
jvm 1 | 2016-01-14 17:08:15,104 INFO - Build request has been processed.
  • replies 1
  • views 1330
  • stars 0
robinshen ADMIN ·
Sorry the documentation has an error. The restful url to update build should be:
"http://<server>/rest/builds" instead of "http://<server>/rest/build"