Automatically deploy code using the svn post-commit hook

Source: Internet
Author: User
Tags svn update

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.