HowTo setup automatic refresh of repositories in Redmine on commit » History » Version 28
Lukas Pirl, 2014-06-26 21:25
1 | 1 | Etienne Massip | h1. HowTo setup automatic refresh of repositories in Redmine on commit |
---|---|---|---|
2 | 4 | Mischa The Evil | |
3 | {{>toc}} |
||
4 | 1 | Etienne Massip | |
5 | 15 | Etienne Massip | 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. |
6 | 1 | Etienne Massip | |
7 | 10 | Maxim Strukov | Examples: |
8 | 1 | Etienne Massip | |
9 | * _/sys/fetch_changesets?key=<your service key>_ fetches changesets for all active projects |
||
10 | 7 | Felix Schäfer | * _/sys/fetch_changesets?id=<project identifier>&key=<your service key>_ fetches changesets from the repository of a specific project |
11 | 1 | Etienne Massip | |
12 | 16 | Mohit Sindhwani | *Notice:* |
13 | 18 | Etienne Massip | * 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 &@. |
14 | 16 | Mohit Sindhwani | * 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@ |
15 | 13 | C. X. | |
16 | 1 | Etienne Massip | See #2925 for original feature request. |
17 | |||
18 | h2. Step 1 : configure Redmine to accept the request |
||
19 | |||
20 | Web service for repositories must by activated in the Administration menu and the generated key will have to be used by the caller in Step 2. |
||
21 | |||
22 | h2. Step 2 : setup a post-commit script on the SCM server |
||
23 | |||
24 | You have to setup a post-commit script which will call the previous URL. |
||
25 | |||
26 | h3. Subversion |
||
27 | |||
28 | 8 | Etienne Massip | 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 : |
29 | <pre><code class="sh"> |
||
30 | 1 | Etienne Massip | #!/bin/sh |
31 | |||
32 | 6 | Jürgen Hörmann | curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>" |
33 | 8 | Etienne Massip | </code></pre> |
34 | 12 | razumuhin map | or if you want to use wget |
35 | <pre><code class="sh"> |
||
36 | 19 | Etienne Massip | wget "http://<redmine url>/sys/fetch_changesets?key=<your service key>" |
37 | 12 | razumuhin map | </code></pre> |
38 | Note: Don`t forget wget in your computer path. |
||
39 | 11 | razumuhin map | |
40 | 1 | Etienne Massip | Or, on a Windows system (2 files) : |
41 | |||
42 | 8 | Etienne Massip | * @post-commit.cmd@ : |
43 | <pre><code class="cmd"> |
||
44 | 2 | Etienne Massip | cscript "%~dp0refresh_redmine.vbs" //Nologo >> "%~dp0refresh_redmine.log" 2>&1 |
45 | 8 | Etienne Massip | </code></pre> |
46 | 1 | Etienne Massip | |
47 | 8 | Etienne Massip | * @refresh_redmine.vbs@ : |
48 | <pre><code class="vbs"> |
||
49 | 1 | Etienne Massip | private const REDMINE_SERVICE_KEY = "<your service key>" |
50 | |||
51 | 15 | Etienne Massip | Call HTTPGet("http://<redmine url>/sys/fetch_changesets?key=" & REDMINE_SERVICE_KEY) |
52 | 1 | Etienne Massip | |
53 | 15 | Etienne Massip | Private Function HTTPGet(sUrl) |
54 | Dim oHTTP |
||
55 | 1 | Etienne Massip | set oHTTP = CreateObject("Microsoft.XMLHTTP") |
56 | 15 | Etienne Massip | oHTTP.open "GET", sUrl, False |
57 | oHTTP.send |
||
58 | HTTPGet = oHTTP.responseText |
||
59 | 1 | Etienne Massip | End Function |
60 | 8 | Etienne Massip | </code></pre> |
61 | 17 | Ruslan Khasanov | or for https |
62 | <pre><code class="vbs"> |
||
63 | private const REDMINE_SERVICE_KEY = "<your service key>" |
||
64 | |||
65 | Call HTTPGet("https://<redmine url>/sys/fetch_changesets?id=<your project id>&key=" & REDMINE_SERVICE_KEY) |
||
66 | |||
67 | Private Function HTTPGet(sUrl) |
||
68 | Dim oHTTP |
||
69 | set oHTTP = CreateObject("MSXML2.ServerXMLHTTP") |
||
70 | oHTTP.open "GET", sUrl, False |
||
71 | oHTTP.setOption 2, 13056 |
||
72 | oHTTP.send |
||
73 | HTTPGet = oHTTP.responseText |
||
74 | End Function |
||
75 | </code></pre> |
||
76 | 9 | András Veres-Szentkirályi | |
77 | 26 | Vincent Lizzi | |
78 | 27 | Vincent Lizzi | Or, on a Windows system: |
79 | 1 | Etienne Massip | |
80 | 27 | Vincent Lizzi | If Ruby is on your system path, simply create a @post-commit.bat@ script file in the hooks sub-directory of the repository: |
81 | |||
82 | <pre><code class="bat"> |
||
83 | ruby -e "require 'open-uri'; open('http://<redmine url>/sys/fetch_changesets?key=<your service key>').read;" |
||
84 | </code></pre> |
||
85 | |||
86 | If Perl is installed, simply create a @post-commit.bat@ script file in the hooks sub-directory of the repository: |
||
87 | 26 | Vincent Lizzi | |
88 | <pre><code class="bat"> |
||
89 | perl -mLWP::Simple -e "$url = 'http://<redmine url>/sys/fetch_changesets?key=<your service key>'; LWP::Simple::get($url);" |
||
90 | </code></pre> |
||
91 | |||
92 | |||
93 | |||
94 | 9 | András Veres-Szentkirályi | h3. Git |
95 | |||
96 | 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: |
||
97 | |||
98 | <pre><code class="sh"> |
||
99 | #!/bin/sh |
||
100 | |||
101 | curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>" |
||
102 | </code></pre> |
||
103 | |||
104 | 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. |
||
105 | |||
106 | Don't forget to make the file(s) executable on UNIXish systems, more information about Git hooks can be found in the "githooks":http://www.kernel.org/pub/software/scm/git/docs/githooks.html man page. |
||
107 | 14 | Hadrien KOHL | |
108 | 25 | Mindaugas Kairys | 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: |
109 | 21 | Mindaugas Kairys | |
110 | <pre><code class="sh"> |
||
111 | #!/bin/sh |
||
112 | |||
113 | 25 | Mindaugas Kairys | cd /<path_to_origin_git_repo>/<your_git_prj.git> |
114 | 22 | Mindaugas Kairys | git push /<redmine_path>/<git_repo>/<your_git_prj.git> master |
115 | 21 | Mindaugas Kairys | curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>" |
116 | 1 | Etienne Massip | </code></pre> |
117 | 23 | Mindaugas Kairys | |
118 | 24 | Mindaugas Kairys | * 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 |
119 | 21 | Mindaugas Kairys | |
120 | 14 | Hadrien KOHL | h3. Only update relevant project |
121 | |||
122 | 20 | Adrien Crivelli | /sys/fetch_changesets accepts id parameter, so you can limit the refresh to the correct project : |
123 | 14 | Hadrien KOHL | |
124 | <pre><code class="sh"> |
||
125 | #!/bin/bash |
||
126 | |||
127 | _apikey=XXXXXXXXXXXXXXXXXXXX |
||
128 | |||
129 | _projectid=${PWD##*/} |
||
130 | _projectid=${_projectid%*.git} |
||
131 | |||
132 | curl "http://<redmine url>/sys/fetch_changesets?key=$_apikey&id=$_projectid"& |
||
133 | </code></pre> |
||
134 | 28 | Lukas Pirl | |
135 | h3. Only update relevant repository |
||
136 | |||
137 | If you can install commit hooks on your repository server, you can use "this":http://www.redmine.org/plugins/redmine_scm_hookhelpers plugin to fetch commits for a certain repository only. |