I have created a Jenkins freestyle project executing Groovy script, inside which I need to call a REST api to validate username and password. How to pass these parameters and use the entered credentials inside the Groovy script.
This is the code I am using to get the REST api called :
def post = new URL("http://xxxx/xxxxx/xxxxx/xxxx?userName=$Username&password=$Password").openConnection()
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
def message = '{"message":"this is a message"}'
post.getOutputStream().write(message.getBytes("UTF-8"))
def postRC = post.getResponseCode()
println(postRC)
But the username and password in the above URL is the one I want from the user building the job. How do I get that?