Hello,

i hope some one can help me.
I have this groovy script:
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 = "name"
def apiToken = "token"
def client = new HttpClient()
client.getState().setCredentials(new 
AuthScope("http://hudson/login?from=%2Fhudson%2F",8080,"realm";),new 
UsernamePasswordCredentials(username, apiToken))
client.params.authenticationPreemptive=true
 
def buildNumber = 2
  println("hello${buildNumber}")
  
def urlDeployment = 
"http://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.setDoAuthentication(true)
get.doAuthentication=true
  println("there "+ get.getDoAuthentication())
  println("wow")
response = get.getResponseBodyAsString()
println(response)

But i do not get the correct answer. I got always:

Authentication required


What is wrong with my script, please help me.

Reply via email to