0
votes

I have two Jobs in Jenkins, one which has a working copy of "subversion/repos/mainframe" and another that has a working copy of "subversion/repos/mainframe/subdir".

I then created a hook on the mainframe repository to call Jenkins on any commit. This hook has been triggering my first Job without a Problem. But the second Job doesn't get triggered at all. The only difference is that the second Job is set to a subdirectory inside the repository and i'd like to keep it that way. Even when i commit a file inside "subversion/repos/mainframe/subdir" the second Job doesn't get polled, only the first.

How can i trigger the second Job with a post-commit hook?

post-commit.cmd in hooks:

\...\post-commit.exe %1 %2

post-commit.exe (cleaned up):

' read Parameters
sArchive = Environment.GetCommandLineArgs(1)
sRevision = Environment.GetCommandLineArgs(2)

' get UUID
Dim process As New Process()
process.StartInfo.FileName = "svnlook.exe"
process.StartInfo.Arguments = "uuid " + sArchive
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.Start()

Dim reader As StreamReader = process.StandardOutput
UUID = reader.ReadLine()
wrGETURL = System.Net.WebRequest.Create(jenkinsTESTURL + UUID.Trim() + "/notifyCommit?rev=" + sRevision)
wrGETURL.Method = "POST"
Dim postData As String = "`svnlook changed --revision " + sRevision + " " + sArchive + "`"
Dim byteArray As Byte() = Text.Encoding.UTF8.GetBytes(postData)
wrGETURL.ContentType = "text/plain;charset=UTF-8"
wrGETURL.ContentLength = byteArray.Length
Dim dataStream As Stream = wrGETURL.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Jenkins Log (only the first Job gets triggered):

Mai 10, 2016 11:37:11 AM INFO jenkins.scm.impl.subversion.SubversionSCMSource$ListenerImpl onNotify
Received post-commit hook from 0e020a5b-918e-1147-8b68-31c6afce54ec for revision 152.138 on paths [look changed --revision 152138 D:\svn\testrepos\mainframe`]

Mai 10, 2016 11:37:11 AM INFO jenkins.scm.impl.subversion.SubversionSCMSource$ListenerImpl onNotify
No subversion consumers for UUID 0e020a5b-918e-1147-8b68-31c6afce54ec

Mai 10, 2016 11:37:11 AM INFO hudson.triggers.SCMTrigger$Runner run
SCM changes detected in PostcommitHook-Test. Triggering  #52

Mai 10, 2016 11:37:20 AM INFO hudson.model.Run execute
PostcommitHook-Test #52 main build action completed: SUCCESS

Edit:

Simply changing the second Job to point to "subversion/repos/mainframe/" works. Then the trigger calls both Jobs. It's just not a workable solution because then it gets called way too many times for commits that shouldn't affect the Job.

2
The post-commit triggers a poll on jobs involving the repo, did you double check poll scm is enabled on the subdirectory job? Did it do a poll and not see a change?Dominik Gebhart
Yes, poll scm is enabled without a schedule.drouning
Is there a menu entry to see the result of the most recent poll? Does it correspond to the time of your commit?Dominik Gebhart
I've added the log, there's an error "No subversion consumers" although it does trigger the first Job correctly.drouning

2 Answers

0
votes

It's not a problem to fire off a job for a sub directory. My guess is that your hook code isn't setup to handle the sub directory. We need to see your post-commit hook code to assess further, though.

0
votes

Managed to get it working. First i set my second Job to point to the main repository at "subversion/repos/mainframe". To ignore any commits not done to the subdir there is an advanced option in the subversion plugin to only include a specific path. By setting that to "/subdir/.*" only commits in that folder or its subfolders trigger the Job.