Recently, I configured a SVN server to save my code for some small projects. The SVN server is also a front-end Web server. So you want to use the POST-commit hook HOOKS of SVN to deploy at the same time as committing code.

The specific steps are as follows:

1. Locate the HOOKS directory for the SVN project. There are several default hook templates in the directory, so we need to create a post-commit file.

2. Post-commit main content

#/bin/bash

REPOS=”$1″ REV=”$2″ WEB_PATH=”/home/fltrpsrv2/www” TEST_PATH=”/home/apache/testx/www.h.cn” export LANG=zh_CN.UTF-8 CURDATE = ` date ` echo “Code Deployed By the at $CURDATE” > > / home/fltrpsrv2 / SVN/www.h.cn/hooks/code_… /usr/local/bin/svn update –username xxx –password xxx /home/apache/htdocs/ >> /home/fltrpsrv2/svn/www.h.cn/hooks/ code_deploy_log

3. We need to Checkout a piece of code to the WEB’s service catalog.

4. After the code CO comes out, you can test the post-commit script. Because SVN hooks execute without any environment variables, we cannot test the code with a simple./post-commit. You must run the sudo su command to switch to the SVN or Apache server and perform the following test

Env -. / post – commit

In this case, the user who runs the SVN update command is the user who runs the SVN or Apache server. Therefore, ensure that the directory where the code is stored has the permission of the user; otherwise, the script cannot be executed. I lost a lot of time because of this permission problem.

Permissions are also explained on the SVN official website, and you can refer to the following materials.

In THE Unix system, if there is no corresponding user, you can also use the C language to write scripts, and give the +S permission to achieve the corresponding purpose, see the details in the attachment.

In addition, using this method to deploy the code does not guarantee the synchronization. When performing SVN update, if there is a folder or file with the same name as the folder in SVN check, the update will fail. Note this.

 

Technorati tags: SVN, Hook,post-commit, automatic deployment

References: 1. SVN Authentication and Auto Update 2. SVN Forum 3