Recently, I configured an SVN server to save some of my code. The SVN server is also a front-end web server. Therefore, we hope to use the svn post-commit hook hooks to deploy the SDK while submitting code.
The procedure is as follows:
1. Find the hooks directory of the svn project. By default, the directory contains several hook templates for corresponding operations. We need to create a post-commit file.
2. Main content of post-commit
#/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 at $ curdate">/home/fltrpsrv2/SVN/www.h.cn/hooks/code_deploy_log
/Usr/local/bin/SVN update -- username XXX -- password xxx/home/Apache/htdocs/>/home/fltrpsrv2/SVN/www.h.cn/hooks/
Code_deploy_log
3. Next we need to checkout a copy of code to the Web service directory.
4. After the code Co is released, you can test the post-commit script. Because SVN hooks does not contain any environment variables during execution, we cannot test the Code through simple./post-commit. You must use commands such as sudo Su to switch to the svn or Apache server to run the user, and use the following method for testing:
Env-./post-commit
In this way, the user who executes the svn update command is the user who runs the svn or Apache server. Therefore, we need to ensure that the code storage directory must have the permissions of the corresponding user. Otherwise, this script cannot be executed. I am suffering a lot of time delay due to this permission problem.
Permissions are also described on the svn official site. You can refer to the following documents.
In Unix systems, if there is no corresponding user, you can also use the C language to write a script and grant the + s permission to achieve the corresponding purpose. For details, see the information in the attachment.
Additionally, using this method to deploy the Code cannot ensure synchronization is complete. When executing SVN update, if the checked folder contains a folder or file with the same name as SVN, the update will fail, note This.
Technorati labels: SVN, Hook, post-commit, automatic deployment
References:
1. SVN authentication and auto update
2. SVN Forum
3. Website Auto Update
4. Hook debuging