HowTo setup automatic refresh of repositories in Redmine on commit¶
- Table of contents
- HowTo setup automatic refresh of repositories in Redmine on commit
Since of version 0.9.0, you can use an HTTP GET submission to automatically refresh Redmine after you committed your modification in your repository.
Examples:
- /sys/fetch_changesets?key=<your service key> fetches changesets for all active projects
- /sys/fetch_changesets?id=<project identifier>&key=<your service key> fetches changesets from the repository of a specific project
- Instead of calling an url, you can use
ruby /path_to_redmine/redmine/script/rails runner "Repository.fetch_changesets" -e production > /dev/null 2>&1 &
. - Note also that project identifier can either be the number of the project, e.g.
id=1
or the identifier name that you gave the project, e.g.,id=mobileapp
See #2925 for original feature request.
Step 1 : configure Redmine to accept the request¶
Web service for repositories must by activated in the Administration menu (Administration - Settings - Repositories - Enable WS for repository management) and the generated API key (referred to "your service key" in the following documentation) will have to be used by the caller in Step 2.
Step 2 : setup a post-commit script on the SCM server¶
You have to setup a post-commit script which will call the previous URL.
Subversion¶
Simply add a post-commit
(or post-commit.cmd
on a Windows system) script file in the hooks sub-directory which contains the HTTP request call :
#!/bin/sh
curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>"
or if you want to use wget
wget "http://<redmine url>/sys/fetch_changesets?key=<your service key>"
Note: Don`t forget wget in your computer path.
Or, on a Windows system (2 files) :
post-commit.cmd
:cscript "%~dp0refresh_redmine.vbs" //Nologo >> "%~dp0refresh_redmine.log" 2>&1
refresh_redmine.vbs
:private const REDMINE_SERVICE_KEY = "<your service key>" Call HTTPGet("http://<redmine url>/sys/fetch_changesets?key=" & REDMINE_SERVICE_KEY) Private Function HTTPGet(sUrl) Dim oHTTP set oHTTP = CreateObject("Microsoft.XMLHTTP") oHTTP.open "GET", sUrl, False oHTTP.send HTTPGet = oHTTP.responseText End Function
or for httpsprivate const REDMINE_SERVICE_KEY = "<your service key>" Call HTTPGet("https://<redmine url>/sys/fetch_changesets?id=<your project id>&key=" & REDMINE_SERVICE_KEY) Private Function HTTPGet(sUrl) Dim oHTTP set oHTTP = CreateObject("MSXML2.ServerXMLHTTP") oHTTP.open "GET", sUrl, False oHTTP.setOption 2, 13056 oHTTP.send HTTPGet = oHTTP.responseText End Function
Or, on a Windows system:
If Ruby is on your system path, simply create a post-commit.bat
script file in the hooks sub-directory of the repository:
ruby -e "require 'open-uri'; open('http://<redmine url>/sys/fetch_changesets?key=<your service key>').read;"
If Perl is installed, simply create a post-commit.bat
script file in the hooks sub-directory of the repository:
perl -mLWP::Simple -e "$url = 'http://<redmine url>/sys/fetch_changesets?key=<your service key>'; LWP::Simple::get($url);"
Git¶
Simply add a post-receive
(even on a Windows system, no extension is required) script file in the hooks sub-directory which contains the HTTP request call:
#!/bin/sh
curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>"
This setup works in the "usual" case, where Redmine's repository is set to a bare Git repository, so no commits can happen directly in there. If you have a rare setup with a non-bare repository linked to Redmine, you need to add the script as a post-commit
hook as well.
Don't forget to make the file(s) executable on UNIXish systems, more information about Git hooks can be found in the githooks man page.
In case a redmine project is configured to work with a mirror repository that resides on the same host as the origin git repository, you can also use a post-receive
hook to update that redmine mirror repository, so the whole script then could be:
#!/bin/sh
cd /<path_to_origin_git_repo>/<your_git_prj.git>
git push /<redmine_path>/<git_repo>/<your_git_prj.git> master
curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>"
- this will also eliminate the need of a mirror synchronization cron script and will help to keep redmine's project repository in sync just after every git push event
Only update relevant project¶
/sys/fetch_changesets accepts id parameter, so you can limit the refresh to the correct project :
#!/bin/bash
_apikey=XXXXXXXXXXXXXXXXXXXX
_projectid=${PWD##*/}
_projectid=${_projectid%*.git}
curl "http://<redmine url>/sys/fetch_changesets?key=$_apikey&id=$_projectid"&
Only update relevant repository¶
If you can install commit hooks on your repository server, you can use this plugin to fetch commits for a certain repository only.
Updated by Tom Rochette over 8 years ago · 29 revisions