1

I'm launching build jobs on a local Jenkins with:

curl -X POST "http://UID:TOKEN@server:port/job/DevGate/build?delay=0sec&json=%7B%22parameter%22%3A+%7B%22name%22%3A+%22DEVGATE_PACKAGELIST%22%2C+%22value%22%3A+%2212345678%3A9%22%7D%2C+%22statusCode%22%3A+%22303%22%2C+%22redirectTo%22%3A+%22.%22%7D&Submit=Build"

which translates into

curl -X POST "http://UID:TOKEN@server:port/job/DevGate/build?delay=0sec&json={"parameter": {"name": "DEVGATE_PACKAGELIST", "value": "12345678:9"}, "statusCode": "303", "redirectTo": "."}&Submit=Build"

UID being userID. TOKEN being API Token given by Jenkins/REST API. And it works. Now, this command is launched inside of a VBScript that mainly gathers data for creation of aforementioned URL. No password needed, and I'd like to keep it that way. The problem: I'd like to avoid using curl and use just native VBScript functionality.

What I've tried so far:

Dim http: Set http = CreateObject("Microsoft.XMLHTTP")
Dim url: url = "http://server:port/job/DevGate/build"
Dim data: data = "delay=0sec&json=%7B%22parameter%22:+%7B%22name%22:+%22DEVGATE_PACKAGELIST%22,+%22value%22:+%22" + the rest of data
'string2try = Base64EncodeString("UID:TOKEN")
'string2try = Base64EncodeString("UID:PASSWORD")
With http
  .Open "POST", url, False
   Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
   Call .SetRequestHeader("oAuth", token)
  .Send data
  'Call .SetRequestHeader("X-Api-Key", token)
  'Call .SetRequestHeader("Authorization", "Bearer " & token)
  'Call .SetRequestHeader("X-Auth-Token", token or string2try)
  'Call .SetRequestHeader("X-Parse-REST-API-Key", token)
End With

Every permutation of that code fails authentication. How to pass my token + uid properly in VBScript without using curl?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 2
    Essentially you need to set `"Authorization", "Basic CREDENTIALS"`, where `CREDENTIALS` is the [base64-encoded](https://stackoverflow.com/a/506992/1630171) value "USERNAME:API_TOKEN" (replace USERNAME with your username and API_TOKEN with your API token). Additional steps are required if [CSRF protection](https://wiki.jenkins.io/display/JENKINS/Remote+access+API) is enabled on the Jenkins server. – Ansgar Wiechers Sep 27 '19 at 10:03
  • 1
    @AnsgarWiechers, you, sir, nailed it. Somehow my `base64` encoding was failing. Thanks! – snakePlantLeaf Sep 30 '19 at 16:59

0 Answers0