Remove a Queue item through a Groovy script

171 views
Skip to first unread message

tiago fernandez

unread,
Aug 7, 2013, 5:04:33 PM8/7/13
to jenkins...@googlegroups.com
Hello,
 
I want to cancel a Queue item through a groovy script.
The script I have is something like this   (I do a post because it is specified that to remove an queue item. And queue item id I obtain it from another part of the code using json api):
 
def urlString = 'http://<jenkins.server>/queue/cancelItem'
def queryString = "id=" + item.id
def url = new URL(urlString)
def connection = url.openConnection()
connection.setRequestMethod("POST")
 
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect()
  
def writer = new OutputStreamWriter(connection.outputStream)
writer.write(queryString)
writer.flush()
writer.close()
 
def inStream = new DataInputStream(connection.getInputStream())
def buffer
while((buffer = inStream.readLine()) != null) {
       println(buffer);
}
 
inStream.close()
connection.close()
 
 
 
 
When I execute this script the item is deleted from the queue, but I get the following error, I think it is because in some point of the code it 'executes' the url deleting the item from the queue, so then it doesn't exist anymore, so when it tries to do the getInputStream it throws the error because the Source URL doesn't exist anymore
Someone has any alternative idea I could implement for this?:
Thanks for the help.
 
 
java.io.FileNotFoundException: http://localhost:8080/queue/item/18/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URLConnection.getContent(Unknown Source)
at java_net_URLConnection$getContent.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Script1.run(Script1.groovy:23)
at groovy.lang.GroovyShell.evaluate(GroovyShell
 

Daniel Beck

unread,
Aug 8, 2013, 12:10:03 AM8/8/13
to jenkins...@googlegroups.com
There is no output. It just sends a redirect to the referer location. In your case. that's undefined, which probably causes it to fail this way. Just ignore any non-error response (or at least, any redirects).
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages