I am trying access one of the Jenkins job's log using groovy script. but getting 403 error. How do I pass the credential to login in below code?
def jsonStr1 = new URL(myEnvUrl+"warnings40Result/api/json?pretty=true").getText()
I am trying access one of the Jenkins job's log using groovy script. but getting 403 error. How do I pass the credential to login in below code?
def jsonStr1 = new URL(myEnvUrl+"warnings40Result/api/json?pretty=true").getText()
You are getting HTTP 403 which stands for Unauthorized attempt.
Possibly there is a login page of Jenkins, you should include it to access your next page. page. Have a check following link:
def jsonStr1 = new URL(myEnvUrl+"warnings40Result/api/json?pretty=true").getText()
I tried all the solution of url:
https://stackoverflow.com/questions/25692515/groovy-built-in-rest-http-client
i think without Login Credentials code we can't access 'jsonStr1'. so i tried below code, now i am able to access but while parsing the value its giving error:
code:200
[PostBuildScript] - Problem occurred: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
my code:
def warningJsonUrl = EnvBuildUrl+"warnings40Result/api/json?token=4eca462899e426937a94006a20561011"
def authString = "admin1:admin1".getBytes().encodeBase64().toString()
def conn = warningJsonUrl.toURL().openConnection()
conn.setRequestProperty( "Authorization", "Basic ${authString}" )
if( conn.responseCode == 200 ) {
println("code:"+conn.responseCode)
def textJsonObj = new JsonSlurper().parseText(conn.content.text)
}
how i will parse as text?