What plugins and plugin features do I need to set in order to get my Jenkins job to trigger a build any time code is committed to an SVN project?
I have installed both the standard SVN plugin as well as the SVN tagging plugin, but I do not see any new features that allow trigger configuration.
This question is related to
svn
continuous-integration
jenkins
jenkins-plugins
I made a tool using Python with some bash to trigger a Jenkins build. Basically you have to collect these two values from post-commit when a commit hits the SVN server:
REPOS="$1"
REV="$2"
Then you use "svnlook dirs-changed $1 -r $2" to get the path which is has just committed. Then from that you can check which repository you want to build. Imagine you have hundred of thousand of projects. You can't check the whole repository, right?
You can check out my script from GitHub.
You can use a post-commit hook.
Put the post-commit hook script in the hooks
folder, create a wget_folder
in your C:\ drive, and put the wget.exe
file in this folder.
Add the following code in the file called post-commit.bat
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
)
echo %REPOS% ----- 1>&2
echo %REV% -- 1>&2
echo %UUID% --1>&2
echo %POST% --1>&2
C:\wget_folder\wget ^
--header="Content-Type:text/plain" ^
--post-data="%POST%" ^
--output-document="-" ^
--timeout=2 ^
http://localhost:9090/job/Test/build/%UUID%/notifyCommit?rev=%REV%
where Test = name of the job
echo
is used to see the value and you can also add exit 2
at the end to know about the issue and whether the post-commit hook script is running or not.
You need to require only one plugin which is the Subversion plugin.
Then simply, go into Jenkins ? job_name ? Build Trigger section ? (i) Trigger build remotely (i.e., from scripts) Authentication token: Token_name
Go to the SVN server's hooks directory, and then after fire the below commands:
cp post-commit.tmpl post-commit
chmod 777 post-commit
chown -R www-data:www-data post-commit
vi post-commit
Note: All lines should be commented Add the below line at last
Syntax (for Linux users):
/usr/bin/curl http://username:API_token@localhost:8081/job/job_name/build?token=Token_name
Syntax (for Windows user):
C:/curl_for_win/curl http://username:API_token@localhost:8081/job/job_name/build?token=Token_name
Source: Stackoverflow.com