Reputation: 99
I am implementing post commit hook in svn repo to trigger jenkins build but getting one exception which is I think in the commit.vb file. I know this is so simple question but I haven't work on vb so no idea about. Following this tutorial - https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin . Also pls help me out in specifying specific job which I need to trigger. I am assuming that with this configuration all the jobs in the jenkins will trigger.
post-commit.bat
SET REPOS=%1
SET REV=%2
SET CSCRIPT=%windir%\system32\cscript.exe
SET VBSCRIPT=C:\Repositories\commit.vbs
SET SVNLOOK=C:\Program Files\VisualSVN Server\bin\svnlook.exe
SET JENKINS=http://localhost:8080/jenkins
"%CSCRIPT%" "%VBSCRIPT%" "%REPOS%" %2 "%SVNLOOK%" %JENKINS%
@pause
commit.vbs
repos = WScript.Arguments.Item(0)
rev = WScript.Arguments.Item(1)
svnlook = WScript.Arguments.Item(2)
jenkins = WScript.Arguments.Item(3)
Set shell = WScript.CreateObject("WScript.Shell")
Set uuidExec = shell.Exec(svnlook & " uuid " & repos)
Do Until uuidExec.StdOut.AtEndOfStream
uuid = uuidExec.StdOut.ReadLine()
Loop
Wscript.Echo "uuid=" & uuid
Set changedExec = shell.Exec(svnlook & " changed --revision " & rev & " " & repos)
Do Until changedExec.StdOut.AtEndOfStream
changed = changed + changedExec.StdOut.ReadLine() + Chr(10)
Loop
Wscript.Echo "changed=" & changed
url = jenkins + "crumbIssuer/api/xml?xpath=concat(//crumbRequestField,"":"",//crumb)"
Set http = CreateObject("Microsoft.XMLHTTP")
http.open "GET", url, False
http.setRequestHeader "Content-Type", "text/plain;charset=UTF-8"
http.send
crumb = null
if http.status = 200 then
crumb = split(http.responseText,":")
end if
url = jenkins + "subversion/" + uuid + "/notifyCommit?rev=" + rev
Wscript.Echo url
Set http = CreateObject("Microsoft.XMLHTTP")
http.open "POST", url, False
http.setRequestHeader "Content-Type", "text/plain;charset=UTF-8"
if not isnull(crumb) then
http.setRequestHeader crumb(0),crumb(1)
http.send changed
if http.status <> 200 then
Wscript.Echo "Error. HTTP Status: " & http.status & ". Body: " & http.responseText
end if
end if
Upvotes: 3
Views: 638
Reputation: 16681
The error is coming from VBScript the two arguments tell you what line and column have triggered the error, in this case, line 4 and column 1.
So the issue is likely (if this is the whole source script)
jenkins = WScript.Arguments.Item(3)
The Subscript Out of Range
error roughly translates to, the current array index you are passing is past the bounds of the array.
So the likelihood is, there is no argument 4 being passed (VBScript arrays start are 0, so 3 is in fact 4).
You can test this yourself with a little alteration to the script to debug the WScript.Arguments
collection. Just add the below code to the top of your script.
Dim i
For i = 0 To WScript.Arguments.Count - 1
WScript.Echo "Index " & i & " = " & WScript.Arguments.Item(i)
Next
It will loop through the list WScript.Arguments
and output what is contained in each.
Testing with
cscript //nologo "test62.vbs" "SVNRepo" "Rev2" "C:\Program Files\VisualSVN Server\bin\svnlook.exe" http://localhost:8080/jenkins
Output:
Index 0 = SVNRepo
Index 1 = Rev2
Index 2 = C:\Program Files\VisualSVN Server\bin\svnlook.exe
Index 3 = http://localhost:8080/jenkins
Upvotes: 4