Hello,

i try that script in the script-console:
import jenkins.*
import jenkins.model.*
import hudson.model.*
import org.apache.commons.httpclient.*
import org.apache.commons.httpclient.auth.*
import org.apache.commons.httpclient.methods.*

def username = "username"
def apiToken = "token"
def client = new HttpClient()
client.state.setCredentials(new 
AuthScope("http://tstbld01c.rz.e-dict.net:8080/hudson/login?from=%2Fhudson%2F",8080,"realm";),new
 
UsernamePasswordCredentials(username, apiToken))
client.params.authenticationPreemptive=true

 
def buildNumber = 2
  println("hello${buildNumber}")
  
def urlDeployment = 
"http://tstbld01c.rz.e-dict.net:8080/hudson/job/selenium2-portalservices-FavoriteGameTests-2.2/";
def urlPart = 
"api/xml?depth=1&xpath=/freeStyleProject/build[action/cause/upstreamProject='dunia'
 
and action/cause/upstreamBuild=${buildNumber}]/number/text()"
 println(urlDeployment +""+urlPart)
  
def get = new GetMethod()
  get.setURI(new URI(urlDeployment+""+urlPart,false))
  println("here")
get.doAuthentication=true
  println("there")
client.executeMethod(get)
  println("wow")
response = get.getResponseBodyAsString()
println(response)

The Result is not what i have expected it got that:

hello2
http://tstbld01c.rz.e-dict.net:8080/hudson/job/selenium2-portalservices-FavoriteGameTests-2.2/api/xml?depth=1&xpath=/freeStyleProject/build[action/cause/upstreamProject='dunia'
 and action/cause/upstreamBuild=2]/number/text()
here
there
wow
<html><head><meta http-equiv='refresh' 
content='1;url=/hudson/login?from=%2Fhudson%2Fjob%2Fselenium2-portalservices-FavoriteGameTests-2.2%2Fapi%2Fxml%3Fdepth%3D1%26xpath%3D%2FfreeStyleProject%2Fbuild%255Baction%2Fcause%2FupstreamProject%3D%27dunia%27%2520and%2520action%2Fcause%2FupstreamBuild%3D2%255D%2Fnumber%2Ftext%28%29'/><script>window.location.replace('/hudson/login?from=%2Fhudson%2Fjob%2Fselenium2-portalservices-FavoriteGameTests-2.2%2Fapi%2Fxml%3Fdepth%3D1%26xpath%3D%2FfreeStyleProject%2Fbuild%255Baction%2Fcause%2FupstreamProject%3D%27dunia%27%2520and%2520action%2Fcause%2FupstreamBuild%3D2%255D%2Fnumber%2Ftext%28%29');</script></head><body
 style='background-color:white; color:white;'>*Authentication 
required*</body></html>


*How can i resolve the authentication problem?*
*
*
Thanks for your help.

Reply via email to