Need help running a Jenkins job from VBScript using JenkinsAPI

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Need help running a Jenkins job from VBScript using JenkinsAPI

D. C.
I have searched all over but haven't found a solution to this. The JenkinsAPI page doesn't provide information on using VBScript either.
I am trying to start a job in Jenkins from a classic ASP web page (so VBScript - code below).  I used wget from examples on the Jenkins API page to get the Jenkins crumb. The testjob is configured with "Trigger builds remotely" and I included the token in the URL string as specified in the examples on the Jenkins API page. I am unsure if the login information is setup correctly in my .setRequestHeader, but the error I am getting is "No valid crumb" even though I include the crumb in the header.  Can anyone tell me if the .setRequestHeaders are in the correct format or anything else that might help me get this to work?  I have also tried using curl to start the job, but that doesn't start the job, but it also doesn't return an error. From what I have found, curl should return an HTTP 201 response to indicate the job was started. I'm not getting that.  I would prefer to start the job from VBScript; curl was just for a test.

VBScript:
--------------
    Dim strJenkinsURL, HttpReq
    strJenkinsURL = "http://<jenkinsURL>/job/testjob/buildWithParameters?token=test&Description=sometext"

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setRequestHeader "UserName", "<jenkinsuser>"
    HttpReq.setRequestHeader "Password", "<userpassword>"
    HttpReq.setRequestHeader "Jenkins-Crumb", "<validcrumb>"
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

Result
---------------------
Status: 403
Response: HTTP ERROR 403
Problem accessing /job/testjob/buildWithParameters. Reason: No valid crumb was included in the request

curl:
------------------------
curl -v --user <jenkinsuser>:<password> -X POST "http://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext" -H "Jenkins-Crumb:<crumb value>"

* timeout on name lookup is not supported
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to jenkinsurl (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'jenkinsuser'
> POST /job/testjob/buildWithParameters?token=test&Description=sometext HTTP/1.1
> Host: jenkinsurl
> Authorization: Basic Y3MyYXV0b3Rlc3Q6QXV0b21hdGlvbjE=
> User-Agent: curl/7.55.0
> Accept: */*
> Jenkins-Crumb:<crumb value>
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: https://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host jenkinsurl left intact

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need help running a Jenkins job from VBScript using JenkinsAPI

slide
I think you want to pass the username/password as part of the Open method call

HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword

In addition, you may need to set an Authorization header, but I am not sure how the  MSXML2.ServerXMLHTTP object handles that if you pass the username/password with the Open call.

You would need to do something like this if just passing it via the Open method doesn't work:

HttpReq.setRequestHeader "Authentication", "Basic " & Base64Encode(strUsername & ":" & strPassword)

On Tue, Jul 9, 2019 at 10:54 AM D. C. <[hidden email]> wrote:
I have searched all over but haven't found a solution to this. The JenkinsAPI page doesn't provide information on using VBScript either.
I am trying to start a job in Jenkins from a classic ASP web page (so VBScript - code below).  I used wget from examples on the Jenkins API page to get the Jenkins crumb. The testjob is configured with "Trigger builds remotely" and I included the token in the URL string as specified in the examples on the Jenkins API page. I am unsure if the login information is setup correctly in my .setRequestHeader, but the error I am getting is "No valid crumb" even though I include the crumb in the header.  Can anyone tell me if the .setRequestHeaders are in the correct format or anything else that might help me get this to work?  I have also tried using curl to start the job, but that doesn't start the job, but it also doesn't return an error. From what I have found, curl should return an HTTP 201 response to indicate the job was started. I'm not getting that.  I would prefer to start the job from VBScript; curl was just for a test.

VBScript:
--------------
    Dim strJenkinsURL, HttpReq
    strJenkinsURL = "http://<jenkinsURL>/job/testjob/buildWithParameters?token=test&Description=sometext"

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setRequestHeader "UserName", "<jenkinsuser>"
    HttpReq.setRequestHeader "Password", "<userpassword>"
    HttpReq.setRequestHeader "Jenkins-Crumb", "<validcrumb>"
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

Result
---------------------
Status: 403
Response: HTTP ERROR 403
Problem accessing /job/testjob/buildWithParameters. Reason: No valid crumb was included in the request

curl:
------------------------
curl -v --user <jenkinsuser>:<password> -X POST "http://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext" -H "Jenkins-Crumb:<crumb value>"

* timeout on name lookup is not supported
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to jenkinsurl (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'jenkinsuser'
> POST /job/testjob/buildWithParameters?token=test&Description=sometext HTTP/1.1
> Host: jenkinsurl
> Authorization: Basic Y3MyYXV0b3Rlc3Q6QXV0b21hdGlvbjE=
> User-Agent: curl/7.55.0
> Accept: */*
> Jenkins-Crumb:<crumb value>
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: https://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host jenkinsurl left intact

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVd%3DGrnaUdGi3i9j4ZtHT1H7Gzsf_1ce2EWqhpaPawSZRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need help running a Jenkins job from VBScript using JenkinsAPI

D. C.
Thanks for the suggestions.  I had actually already tried "HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword" and it didn't help.  Since the error returned has to do with the crumb (403 No valid crumb was included), I hoped the auth part was actually working, but maybe not.  I have tried again with passing the username/password as part of the Open method, but still no luck there.

I tried the .setRequestHeader "Authentication" like you showed but it returns "Type mismatch: 'Base64Encode'" so something is wrong with the syntax.


On Tuesday, July 9, 2019 at 2:06:57 PM UTC-5, slide wrote:
I think you want to pass the username/password as part of the Open method call

HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword

In addition, you may need to set an Authorization header, but I am not sure how the  MSXML2.ServerXMLHTTP object handles that if you pass the username/password with the Open call.

You would need to do something like this if just passing it via the Open method doesn't work:

HttpReq.setRequestHeader "Authentication", "Basic " & Base64Encode(strUsername & ":" & strPassword)

On Tue, Jul 9, 2019 at 10:54 AM D. C. <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="HUYSadpvCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">donc...@...> wrote:
I have searched all over but haven't found a solution to this. The JenkinsAPI page doesn't provide information on using VBScript either.
I am trying to start a job in Jenkins from a classic ASP web page (so VBScript - code below).  I used wget from examples on the Jenkins API page to get the Jenkins crumb. The testjob is configured with "Trigger builds remotely" and I included the token in the URL string as specified in the examples on the Jenkins API page. I am unsure if the login information is setup correctly in my .setRequestHeader, but the error I am getting is "No valid crumb" even though I include the crumb in the header.  Can anyone tell me if the .setRequestHeaders are in the correct format or anything else that might help me get this to work?  I have also tried using curl to start the job, but that doesn't start the job, but it also doesn't return an error. From what I have found, curl should return an HTTP 201 response to indicate the job was started. I'm not getting that.  I would prefer to start the job from VBScript; curl was just for a test.

VBScript:
--------------
    Dim strJenkinsURL, HttpReq
    strJenkinsURL = "http://<jenkinsURL>/job/testjob/buildWithParameters?token=test&Description=sometext"

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setRequestHeader "UserName", "<jenkinsuser>"
    HttpReq.setRequestHeader "Password", "<userpassword>"
    HttpReq.setRequestHeader "Jenkins-Crumb", "<validcrumb>"
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

Result
---------------------
Status: 403
Response: HTTP ERROR 403
Problem accessing /job/testjob/buildWithParameters. Reason: No valid crumb was included in the request

curl:
------------------------
curl -v --user <jenkinsuser>:<password> -X POST "<a href="http://jenkinsurl/job/testjob/buildWithParameters?token=test&amp;Description=sometext" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUPmu03lcgUnGJaT9sktAnZEOsxw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUPmu03lcgUnGJaT9sktAnZEOsxw&#39;;return true;">http://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext" -H "Jenkins-Crumb:<crumb value>"

* timeout on name lookup is not supported
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to jenkinsurl (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'jenkinsuser'
> POST /job/testjob/buildWithParameters?token=test&Description=sometext HTTP/1.1
> Host: jenkinsurl
> Authorization: Basic Y3MyYXV0b3Rlc3Q6QXV0b21hdGlvbjE=
> User-Agent: curl/7.55.0
> Accept: */*
> Jenkins-Crumb:<crumb value>
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: <a href="https://jenkinsurl/job/testjob/buildWithParameters?token=test&amp;Description=sometext" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGzFyGWrTvJUovAmq_TfUaEpQsWPQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGzFyGWrTvJUovAmq_TfUaEpQsWPQ&#39;;return true;">https://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host jenkinsurl left intact

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="HUYSadpvCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
Website: <a href="http://earl-of-code.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;">http://earl-of-code.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need help running a Jenkins job from VBScript using JenkinsAPI

slide
You would have to implement a function to base64 encode the data (I should have mentioned that in my previous post). 

On Tue, Jul 9, 2019 at 2:41 PM D. C. <[hidden email]> wrote:
Thanks for the suggestions.  I had actually already tried "HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword" and it didn't help.  Since the error returned has to do with the crumb (403 No valid crumb was included), I hoped the auth part was actually working, but maybe not.  I have tried again with passing the username/password as part of the Open method, but still no luck there.

I tried the .setRequestHeader "Authentication" like you showed but it returns "Type mismatch: 'Base64Encode'" so something is wrong with the syntax.


On Tuesday, July 9, 2019 at 2:06:57 PM UTC-5, slide wrote:
I think you want to pass the username/password as part of the Open method call

HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword

In addition, you may need to set an Authorization header, but I am not sure how the  MSXML2.ServerXMLHTTP object handles that if you pass the username/password with the Open call.

You would need to do something like this if just passing it via the Open method doesn't work:

HttpReq.setRequestHeader "Authentication", "Basic " & Base64Encode(strUsername & ":" & strPassword)

On Tue, Jul 9, 2019 at 10:54 AM D. C. <[hidden email]> wrote:
I have searched all over but haven't found a solution to this. The JenkinsAPI page doesn't provide information on using VBScript either.
I am trying to start a job in Jenkins from a classic ASP web page (so VBScript - code below).  I used wget from examples on the Jenkins API page to get the Jenkins crumb. The testjob is configured with "Trigger builds remotely" and I included the token in the URL string as specified in the examples on the Jenkins API page. I am unsure if the login information is setup correctly in my .setRequestHeader, but the error I am getting is "No valid crumb" even though I include the crumb in the header.  Can anyone tell me if the .setRequestHeaders are in the correct format or anything else that might help me get this to work?  I have also tried using curl to start the job, but that doesn't start the job, but it also doesn't return an error. From what I have found, curl should return an HTTP 201 response to indicate the job was started. I'm not getting that.  I would prefer to start the job from VBScript; curl was just for a test.

VBScript:
--------------
    Dim strJenkinsURL, HttpReq
    strJenkinsURL = "http://<jenkinsURL>/job/testjob/buildWithParameters?token=test&Description=sometext"

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setRequestHeader "UserName", "<jenkinsuser>"
    HttpReq.setRequestHeader "Password", "<userpassword>"
    HttpReq.setRequestHeader "Jenkins-Crumb", "<validcrumb>"
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

Result
---------------------
Status: 403
Response: HTTP ERROR 403
Problem accessing /job/testjob/buildWithParameters. Reason: No valid crumb was included in the request

curl:
------------------------
curl -v --user <jenkinsuser>:<password> -X POST "http://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext" -H "Jenkins-Crumb:<crumb value>"

* timeout on name lookup is not supported
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to jenkinsurl (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'jenkinsuser'
> POST /job/testjob/buildWithParameters?token=test&Description=sometext HTTP/1.1
> Host: jenkinsurl
> Authorization: Basic Y3MyYXV0b3Rlc3Q6QXV0b21hdGlvbjE=
> User-Agent: curl/7.55.0
> Accept: */*
> Jenkins-Crumb:<crumb value>
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: https://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host jenkinsurl left intact

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVcYdQ6j0Ejuz1L-9ffCWW167y7knVVDuz1Vy7bu_4xgew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need help running a Jenkins job from VBScript using JenkinsAPI

D. C.
After piecing together many suggestions with some trial and error, I was finally able to get the Jenkins job to run remotely with the VBScript (ASP) code below (with variables set to proper values such as strCrumb).  The returned Status will be 201 for success.  The Base64 functions were taken from https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript

    Dim strJenkinsURL, strParam1, strParam2, strCrumb, strUsername, strPassword
    strJenkinsURL = "https://<jenkinsURL>/job/testjob/buildWithParameters?token=test&param1="& strParam1 &"&param2="& strParam2

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setOption 2, 13056
    HttpReq.setRequestHeader "Jenkins-Crumb", strCrumb
    HttpReq.setRequestHeader "Authorization", "Basic "& Base64Encode(strUsername &":"& strPassword)
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

    Function Base64Encode(sText)
        Dim oXML, oNode
        Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
        Set oNode = oXML.CreateElement("base64")
        oNode.dataType = "bin.base64"
        oNode.nodeTypedValue = Stream_StringToBinary(sText)
        Base64Encode = oNode.text
        Set oNode = Nothing
        Set oXML = Nothing
    End Function

    Private Function Stream_StringToBinary(Text)
        Const adTypeText = 2
        Const adTypeBinary = 1
        Dim BinaryStream 'As New Stream
        Set BinaryStream = CreateObject("ADODB.Stream")
        BinaryStream.Type = adTypeText
        BinaryStream.CharSet = "us-ascii"
        BinaryStream.Open
        BinaryStream.WriteText Text
        BinaryStream.Position = 0
        BinaryStream.Type = adTypeBinary
        BinaryStream.Position = 0
        Stream_StringToBinary = BinaryStream.Read
        Set BinaryStream = Nothing
    End Function




On Tuesday, July 9, 2019 at 5:59:57 PM UTC-5, slide wrote:
You would have to implement a function to base64 encode the data (I should have mentioned that in my previous post). 

On Tue, Jul 9, 2019 at 2:41 PM D. C. <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="tGSDXpF8CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">donc...@...> wrote:
Thanks for the suggestions.  I had actually already tried "HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword" and it didn't help.  Since the error returned has to do with the crumb (403 No valid crumb was included), I hoped the auth part was actually working, but maybe not.  I have tried again with passing the username/password as part of the Open method, but still no luck there.

I tried the .setRequestHeader "Authentication" like you showed but it returns "Type mismatch: 'Base64Encode'" so something is wrong with the syntax.


On Tuesday, July 9, 2019 at 2:06:57 PM UTC-5, slide wrote:
I think you want to pass the username/password as part of the Open method call

HttpReq.Open "POST", strJenkinsURL, False, strUsername, strPassword

In addition, you may need to set an Authorization header, but I am not sure how the  MSXML2.ServerXMLHTTP object handles that if you pass the username/password with the Open call.

You would need to do something like this if just passing it via the Open method doesn't work:

HttpReq.setRequestHeader "Authentication", "Basic " & Base64Encode(strUsername & ":" & strPassword)

On Tue, Jul 9, 2019 at 10:54 AM D. C. <[hidden email]> wrote:
I have searched all over but haven't found a solution to this. The JenkinsAPI page doesn't provide information on using VBScript either.
I am trying to start a job in Jenkins from a classic ASP web page (so VBScript - code below).  I used wget from examples on the Jenkins API page to get the Jenkins crumb. The testjob is configured with "Trigger builds remotely" and I included the token in the URL string as specified in the examples on the Jenkins API page. I am unsure if the login information is setup correctly in my .setRequestHeader, but the error I am getting is "No valid crumb" even though I include the crumb in the header.  Can anyone tell me if the .setRequestHeaders are in the correct format or anything else that might help me get this to work?  I have also tried using curl to start the job, but that doesn't start the job, but it also doesn't return an error. From what I have found, curl should return an HTTP 201 response to indicate the job was started. I'm not getting that.  I would prefer to start the job from VBScript; curl was just for a test.

VBScript:
--------------
    Dim strJenkinsURL, HttpReq
    strJenkinsURL = "http://<jenkinsURL>/job/testjob/buildWithParameters?token=test&Description=sometext"

    Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    HttpReq.Open "POST", strJenkinsURL, False
    HttpReq.setRequestHeader "UserName", "<jenkinsuser>"
    HttpReq.setRequestHeader "Password", "<userpassword>"
    HttpReq.setRequestHeader "Jenkins-Crumb", "<validcrumb>"
    HttpReq.Send
    Response.Write "<br>Status: "& HttpReq.Status & vbNewline
    Response.Write "<br>Response: "& HttpReq.responseText & vbNewline

Result
---------------------
Status: 403
Response: HTTP ERROR 403
Problem accessing /job/testjob/buildWithParameters. Reason: No valid crumb was included in the request

curl:
------------------------
curl -v --user <jenkinsuser>:<password> -X POST "<a href="http://jenkinsurl/job/testjob/buildWithParameters?token=test&amp;Description=sometext" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUPmu03lcgUnGJaT9sktAnZEOsxw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUPmu03lcgUnGJaT9sktAnZEOsxw&#39;;return true;">http://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext" -H "Jenkins-Crumb:<crumb value>"

* timeout on name lookup is not supported
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to jenkinsurl (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'jenkinsuser'
> POST /job/testjob/buildWithParameters?token=test&Description=sometext HTTP/1.1
> Host: jenkinsurl
> Authorization: Basic Y3MyYXV0b3Rlc3Q6QXV0b21hdGlvbjE=
> User-Agent: curl/7.55.0
> Accept: */*
> Jenkins-Crumb:<crumb value>
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: <a href="https://jenkinsurl/job/testjob/buildWithParameters?token=test&amp;Description=sometext" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGzFyGWrTvJUovAmq_TfUaEpQsWPQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkinsurl%2Fjob%2Ftestjob%2FbuildWithParameters%3Ftoken%3Dtest%26Description%3Dsometext\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGzFyGWrTvJUovAmq_TfUaEpQsWPQ&#39;;return true;">https://jenkinsurl/job/testjob/buildWithParameters?token=test&Description=sometext
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host jenkinsurl left intact

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/acd05793-f5c3-47c1-9049-75835b7933a2%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
Website: <a href="http://earl-of-code.com" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;">http://earl-of-code.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="tGSDXpF8CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/40ab289f-2d68-465d-8c00-4791968a38a0%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
Website: <a href="http://earl-of-code.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6n4PgqhQTRQjanfDfEls_aRabFg&#39;;return true;">http://earl-of-code.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a149cc39-06a9-42b0-bf84-abcf16bce964%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.