Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 下标超出范围<;4,1>;_Vbscript - Fatal编程技术网

Vbscript 下标超出范围<;4,1>;

Vbscript 下标超出范围<;4,1>;,vbscript,Vbscript,我正在svn repo中实现post-commit钩子来触发jenkins build,但有一个异常,我认为是在commit.vb文件中。我知道这是一个很简单的问题,但我还没有在vb上工作,所以不知道。在本教程之后-。也请帮我指定具体的工作,我需要触发。我假设通过这种配置,jenkins中的所有作业都将触发 post-commit.bat SET REPOS=%1 SET REV=%2 SET CSCRIPT=%windir%\system32\cscript.exe SET VBSCRIPT=

我正在svn repo中实现post-commit钩子来触发jenkins build,但有一个异常,我认为是在commit.vb文件中。我知道这是一个很简单的问题,但我还没有在vb上工作,所以不知道。在本教程之后-。也请帮我指定具体的工作,我需要触发。我假设通过这种配置,jenkins中的所有作业都将触发

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
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”)
设置uuidExec=shell.Exec(svnlook&uuid&repos)
直到uuidExec.StdOut.AtEndOfStream
uuid=uuidExec.StdOut.ReadLine()
环
Wscript.Echo“uuid=”&uuid
Set changedExec=shell.Exec(svnlook&changed--revision&rev&repos)
直到更改dexec.StdOut.AtEndOfStream为止
changed=changed+changedExec.StdOut.ReadLine()+Chr(10)
环
Wscript.Echo“changed=“&changed
url=jenkins+“crumpIssuer/api/xml?xpath=concat(//crumpRequestField,”:“”,//crump)”
设置http=CreateObject(“Microsoft.XMLHTTP”)
http.open“GET”,url,False
http.setRequestHeader“内容类型”、“文本/普通;字符集=UTF-8”
http.send
crump=null
如果http.status=200,则
crumb=split(http.responseText,“:”)
如果结束
url=jenkins+“subversion/”+uuid+“/notifyCommit?rev=“+rev
Echo url
设置http=CreateObject(“Microsoft.XMLHTTP”)
http.open“POST”,url,False
http.setRequestHeader“内容类型”、“文本/普通;字符集=UTF-8”
如果不是isnull(crump),则
http.setRequestHeader碎屑(0),碎屑(1)
http.send已更改
如果是http.status 200,那么
Wscript.Echo“Error.HTTP Status:&HTTP.Status&.”Body:&HTTP.responseText
如果结束
如果结束

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

因此问题很可能出现(如果这是整个源代码脚本)

下标超出范围
错误大致转化为,您传递的当前数组索引超过了数组的边界

因此,可能没有传递参数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
输出:

索引0=SVNRepo
索引1=Rev2
索引2=C:\Program Files\VisualSVN Server\bin\svnlook.exe
指数3=http://localhost:8080/jenkins

%CSCRIPT%、%VBSCRIPT%、%REPOS%、%REV%、%SVNLOOK%、%JENKINS%“
这很容易调试,只需编写aq
,供
循环检查
WScript.Arguments
集合,我从错误中猜测您没有得到您期望的所有参数。@AnsgarWiechers我认为
WScript.arguments
没有区分带引号的参数和不带引号的参数?加上
%REV%
只是
%2
那么为什么不起作用呢?@All-不知道vbscript:(@Lankymart如果
%2
为空,则参数
%SVNLOOK%”
%JENKINS%
被有效地向左移动了一位。将参数放在双引号中可以避免这种情况,因为空参数/变量会变成空字符串,而不是完全从语句中消失。我使用
%REV%
只是因为
%2
已经分配给它。使用
“%~2”
也会有同样的效果。仍然无法获得解决方案。请帮助我out@VaibhavDalela听着,这不是一个解决方案,我试图帮助你调试这个问题。你是否设法添加了代码并再次运行它,输出是什么?它应该可以帮助你确定是否有任何参数没有正确传递。@VaibhavDalela在这种情况下,h是什么如前所述,参数向左移动,因此
WScript.arguments.Item(3)
不存在。在该注释中,他建议使用
“%CSCRIPT%”“%VBSCRIPT%”“%REPOS%”“%REV%”“%SVNLOOK%”“%JENKINS%”
在批处理脚本中,因此即使
%2
为空,它也将在参数中作为空字符串返回。@VaibhavDalela尝试一下,然后再次运行调试代码输出是什么?是的,它现在正在工作,谢谢,但我的作业没有在jenkins中执行…:-(
Dim i
For i = 0 To WScript.Arguments.Count - 1
  WScript.Echo "Index " & i & " = " & WScript.Arguments.Item(i)
Next