gpt4 book ai didi

vbscript - 下标超出范围 <4,1>

转载 作者:行者123 更新时间:2023-12-01 12:24:38 27 4
gpt4 key购买 nike

我正在 svn repo 中实现提交后 Hook 以触发 jenkins 构建,但我认为在 commit.vb 文件中出现一个异常。我知道这是一个非常简单的问题,但我没有在 vb 上工作,所以不知道。按照本教程 - https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin .也请帮助我指定我需要触发的特定工作。我假设使用此配置将触发 jenkins 中的所有作业。

提交后.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

提交.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

最佳答案

错误来自 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

关于vbscript - 下标超出范围 <4,1>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41261499/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com