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
 

-- 
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-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to