I have a small issue regarding the Jenkins build after SVN commit.
i have configured a jenkins.vb script to call after the post-commit hook, but the build is not triggering after the commit.
When i pass the Repository path and revision # through command line , the build gets triggered.
Can any one help me out of this issue. please find below the post-commit hook and jenkins.vbs file
Jenkins Url to trigger build : http:\server-name\job\branchname\build?delay=2sec
post commit hook :
@echo on
rem POST-COMMIT HOOK
set REPOS=%1
set REV=%2
SET CSCRIPT=C:\WINNT\system32\cscript.exe
SET VBSCRIPT=D:\SVN\hooks\post-commit-hook-jenkins.vbs
SET SVNLOOK=C:\Subversion\bin\svnlook.exe %VBSCRIPT% %REPOS% %REV%
Jenkins.vbs
repos = WScript.Arguments.Item(0)
rev = WScript.Arguments.Item(1)
svnlook = "C:\Subversion\bin\svnlook.exe"
jenkinsBaseUrl = **JenkinsURL** (unable to paste the URL would be in this format "URL:8080")
Set shell = WScript.CreateObject("WScript.Shell")
Set uuidExec = shell.Exec(svnlook & " uuid " & repos)
Do Until uuidExec.StdOut.AtEndOfStream
uuid = uuidExec.StdOut.ReadLine()
Loop
' Create a list of all branches that have been modified.
Dim branches()
ReDim Preserve branches(-1)
Set changedExec = shell.Exec(svnlook & " changed --revision " & rev & " " & repos)
Do Until changedExec.StdOut.AtEndOfStream
fileChanged = changedExec.StdOut.ReadLine()
' Get the branch names if any
If InStr(fileChanged, "source/branches/") Then
branchStartIndex = InStr(fileChanged, "source/branches/") + 38
branch = Mid(fileChanged, branchStartIndex)
branchEndIndex = InStr(branch, "/") - 1
branch = Left(branch, branchEndIndex)
branchFound = False
For count = 0 to UBound(branches)
If (CStr(branches(count)) = CStr(branch)) Then
branchFound = True
End If
Next
' Add the branch if it was not previously added
If branchFound = False Then
ReDim Preserve branches(UBound(branches) + 1)
branches(UBound(branches)) = branch
End If
End If
Loop
' the above code gives the branch name in which the check-in has been done (THE ABOVE CODE WORKS FINE)
' Fire out a build for every branch that has changed
For count = LBound(branches) to UBound(branches)
url = jenkinsBaseUrl + "/job/" & branches(count) & "/build?delay=0sec"
Set http = CreateObject("Microsoft.XMLHTTP")
http.open "POST", url, False
http.setRequestHeader "Content-Type", "text/plain;charset=UTF-8"
http.send changed
Next
Best Answer
You will need to specify the url to the repository (with the full path the specific branch) that you want to use in "Source Code Management", as discussed in the comments.
You can use polling if you want, which will have check all paths specified for new changes, at the specified regular intervals and trigger a new build when a new revision is detected.
Using a post-commit hook works just as well, and might be even necessary, e.g. if you don't want to constantly poll the repository for changes (maybe because the changes are infrequent), or if you need to specify multiple paths under Source Code Management that are needed for the project, but you don't want to trigger a build for changes in some of them.
The wiki page of the Subversion Plugin provides some nice examples for post-commit hooks, including a VBScript - note that it doesn't use the build trigger url as you did in your script, but notifies the jenkins server of the commit to the specific svn repository.