下标超出范围< 4,1>

时间:2016-12-21 11:14:46

标签: vbscript

我在svn repo中实现post commit hook来触发jenkins构建,但是我认为在commit.vb文件中有一个异常。我知道这是一个非常简单的问题,但我还没有在vb上工作,所以不知道。遵循本教程 - https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin。另外请帮我指出我需要触发的具体工作。我假设使用此配置,jenkins中的所有作业都将触发。

-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

1 个答案:

答案 0 :(得分:4)

错误来自VBScript,两个参数告诉您哪些行和列触发了错误,在本例中为第4行和第1列。

所以问题可能是(如果这是整个源脚本)

jenkins = WScript.Arguments.Item(3)

Subscript Out of Range错误大致转换为,您传递的当前数组索引超出了数组的范围。

所以可能性是,没有参数4被传递(VBScript数组开始为0,所以3实际上是4)

您可以通过对脚本进行一些更改来自行测试,以调试WScript.Arguments集合。只需将以下代码添加到脚本的顶部即可。

Dim i
For i = 0 To WScript.Arguments.Count - 1
  WScript.Echo "Index " & i & " = " & WScript.Arguments.Item(i)
Next

它将循环遍历列表WScript.Arguments并输出每个列表中包含的内容。

使用

进行测试
cscript //nologo "test62.vbs" "SVNRepo" "Rev2" "C:\Program Files\VisualSVN Server\bin\svnlook.exe" http://localhost:8080/jenkins

输出:

Index 0 = SVNRepo
Index 1 = Rev2
Index 2 = C:\Program Files\VisualSVN Server\bin\svnlook.exe
Index 3 = http://localhost:8080/jenkins
相关问题