我知道有很多类似的帖子,但我还没有找到解决方案,并且其他帖子中提出的建议和解决方案与我所看到的不一致。我在Eclipse中有一个项目,当我从该项目签入到Subversion服务器(即VisualSVN Server 2.5.3)的变化时,我想让我们的Jenkins持续集成服务器(即詹金斯1.546)接受这一改变并开始新的构建。我不想从詹金斯投票。Post-Commit Hook触发自动Jenkins构建
我一直在遵循this article中的步骤。这是我的post-commit钩子脚本:
repos = WScript.Arguments.Item(0)
rev = WScript.Arguments.Item(1)
svnlook = WScript.Arguments.Item(2)
jenkins = WScript.Arguments.Item(3)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Program Files (x86)\VisualSVN Server\log.txt")
objFile.Writeline "repos=" & repos
objFile.Writeline "rev=" & rev
objFile.Writeline "svnlook=" & svnlook
objFile.Writeline "jenkins=" & jenkins
Set shell = WScript.CreateObject("WScript.Shell")
Set uuidExec = shell.Exec(svnlook & " uuid " & repos)
Do Until uuidExec.StdOut.AtEndOfStream
uuid = uuidExec.StdOut.ReadLine()
Loop
objFile.Writeline "uuid=" & uuid
Set changedExec = shell.Exec(svnlook & " changed --revision " & rev & " " & repos)
Do Until changedExec.StdOut.AtEndOfStream
changed = changed + changedExec.StdOut.ReadLine() + Chr(10)
Loop
objFile.Writeline "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
objFile.Writeline "rev url=" & url
objFile.Writeline "http.status=" & http.status
objFile.Writeline "http.responseText=" & http.responseText
if http.status = 200 then
crumb = split(http.responseText,":")
end if
url = jenkins + "subversion/" + uuid + "/notifyCommit?rev=" + rev + "&token=pinkfloyd65"
objFile.Writeline "url=" & url
if not isnull(crumb) then
objFile.Writeline "crumb(0)=" & crumb(0)
objFile.Writeline "crumb(1)=" & crumb(1)
end if
if isnull(crumb) then
objFile.Writeline "crumb=null"
end if
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
objFile.Writeline "Error. HTTP Status: " & http.status & ". Body: " & http.responseText
end if
if http.status = 200 then
objFile.Writeline "HTTP Status: " & http.status & ".\n Body: " & http.responseText
end if
end if
的问题是,虽然上述POST
命令最终得到一个200
回响应,工作从来没有揭开序幕。没有事情发生。好吧,让我们来检查Jenkins的作业配置;也许我错过了一个设置或其他东西。那么,在“构建触发器”部分下,我已经选中了“触发器远程构建(例如,来自脚本)”的选项,并且我还提供了一个身份验证令牌。但是,这部分下方的方向看,从不同的就是我一直在做:
使用下面的URL来触发建立远程:
JENKINS_URL/job/<job-name>/build?token=TOKEN_NAME
或/buildWithParameters?token=TOKEN_NAME
可选附加&cause=Cause+Text
提供将被包含在记录文本构建原因。
因此,似乎我看到的指令集之间存在一个增量,我不知道如何缩小这个差距。遵循Jenkins作业配置页面上的说明似乎很明显,但我不知道如何获得作业名称,而不是UUID。
另一件需要注意的是我的存储库设置。由于许多团体和部门都使用CI服务器,因此我认为自己会很聪明,并创建一个顶级存储库来容纳我的部门项目。所以,我有一个设置是这样的:
VisualSVN Server
-- Repositories
-- Project_A
-- Project_B
-- <my-department>
-- DepartmentProject_A
-- DepartmentProject_B
如果存储库结构也加入到我的问题,在这里我不知道,但我觉得我应该能找出哪些特定的存储库的任何变化是从哪里来的。如果这是真的,那么我可以调整我的脚本以使用作业名称而不是UUID,然后按照CI服务器配置页上显示的明确说明进行操作。当我在我的vbs脚本中记录传入的repos
变量时,它指向顶级部门存储库,而不是项目的子存储库(即D:\<visual-svn-repos>\<my-department>
而不是D:\<visual-svn-repos>\<my-department>\DepartmentProject_B
)。
任何帮助将不胜感激,谢谢你们。
第一个是它:我还需要conf将工作配置为轮询scm,不提供时间表。我不知道我是如何错过了这个blurb,我想我不如我想象的那么彻底。无论如何,谢谢你,scaytrase! – liltitus27