Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triggering Jenkins builds remotely with post-commit hook on Windows

I'm setting up my Subversion post-commit hook to trigger a Jenkins build remotely when a commit is made.

First I changed post-commit.tmpl to post-commit.bat and then:

I tried this first:

SET REPOS=%1
SET REV=%2
C:/wget_for_win/wget http://localhost:8080/jenkins/job/my_project/build

Then I committed some code, and it worked as expected. But this will only build one project, but I want it more flexible so I changed post-commit.bat to the one I found on the Jenkins Subversion Plugin page:

SET REPOS=%1
SET REV=%2
SET UUID=`svnlook uuid %REPOS%`
C:/wget_for_win/wget \
 --header="Content-Type:text/plain;charset=UTF-8"
 --post-data="svnlook changed --revision %REV% %REPOS%"
 --output-document="-"
 --timeout=2
 http://localhost:8080/jenkins/subversion/%UUID%/notifyCommit?rev=%REV%

But this one doesn't work. It didn't trigger Jenkins to build any more. What did I do wrong in the second script?

I think the problem exists in running "svnlook" in the batch file. I run svnlook uuid [REPO LOCATION] in cmd, and it shows the id. Then I put it in a batch file:

SET UUID=svnlook uuid [REPO LOCATION]
ECHO %UUID%

Running the above batch file doesn't output the id. It shows just svnlook uuid [REPO LOCATION].

like image 461
Min Naing Oo Avatar asked Dec 06 '13 05:12

Min Naing Oo


1 Answers

Finally my post-commit.bat looks like:

SET REPOS=%1
SET REV=%2

FOR /f "tokens=*" %%a IN (
'svnlook uuid %REPOS%'
) DO (
SET UUID=%%a
)

FOR /f "tokens=*" %%b IN (
'svnlook changed --revision %REV% %REPOS%'
) DO (
SET POST=%%b
)

C:\wget_for_win\wget ^
    --header="Content-Type:text/plain;charset=UTF-8" ^
    --post-data="%POST%" ^
    --output-document="-" ^
    --timeout=2 ^
    http://localhost:8080/jenkins/subversion/%UUID%/notifyCommit?rev=%REV%

The post-commit hook is working now.

  • For those who want the Windows version of wget, use WGET for Windows.
like image 164
Min Naing Oo Avatar answered Sep 21 '22 08:09

Min Naing Oo