Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the hooks function of SVN to update code automatically

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to configure SVN's hooks function to automatically update the code, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

What is the use of SVN hooks?

The traditional WEB website code release basically depends on manual operation.

The whole process is as follows:

Develop local environment development code

Submit SVN version library

Then upload the local environment code using the tool to the directory to be released

Back up the original WEB site code directory

Release the new code to the WEB directory

Based on the problem of this kind of repetitive operation, in order to improve efficiency, SVN hooks function is introduced.

Configure SVN hooks

SVN installation will not be discussed here. If you need to know, please refer to the previous article (link below)

Https://mp.weixin.qq.com/s?__biz=MzI0MDQ4MTM5NQ==&mid=2247484395&idx=1&sn=fa514768d628649a104b32ba140087e4&chksm=e91b66f7de6cefe1cee310357feb9e26f694de3809bb5b89917ebb17421e96598eb4dcda7fac#rd

Installation is complete, start configuring the hooks feature

[root@centos ~] # cd / svndata/doc/hooks

[root@centos hooks] # ll

Total 40

-rw-r--r-- 1 root root 1977 Jun 8 23:50 post-commit.tmpl

-rw-r--r-- 1 root root 1638 Jun 8 23:50 post-lock.tmpl

-rw-r--r-- 1 root root 2289 Jun 8 23:50 post-revprop-change.tmpl

-rw-r--r-- 1 root root 1567 Jun 8 23:50 post-unlock.tmpl

-rw-r--r-- 1 root root 3426 Jun 8 23:50 pre-commit.tmpl

-rw-r--r-- 1 root root 2410 Jun 8 23:50 pre-lock.tmpl

-rw-r--r-- 1 root root 2786 Jun 8 23:50 pre-revprop-change.tmpl

-rw-r--r-- 1 root root 2100 Jun 8 23:50 pre-unlock.tmpl

-rw-r--r-- 1 root root 2780 Jun 8 23:50 start-commit.tmpl

Back up the configuration file

[root@centos hooks] # cp post-commit.tmpl post-commit

[root@centos hooks] # chmod + x post-commit

Modify post-commit configuration file

[root@centos hooks] # vim post-commit

#! / bin/sh

REPOS= "$1"

REV= "$2"

Export LC_CTYPE= "en_US.UTF-8"

Export LC_ALL=

LOCALPATH= "/ svncode/test/"

WEBPATH=/usr/local/apache-tomcat-8.5.9/webapps/

DATE= `date +% F`

SVN=/usr/bin/svn

[!-d ${LOCALPATH}] & & mkdir ${LOCALPATH}-p

# # update code

$SVN update ${LOCALPATH}-username=test-password=test123

# backup web dir

Cd / usr/local/apache-tomcat-8.5.9/webapps/

Mv test test.$ {DATE}

# # update code and restart Tomcat service

Ln-s $LOCALPATH $WEBPATH

Cd / usr/local/apache-tomcat-8.5.9/bin/

. / shutdown.sh

Sleep 2

. / startup.sh

Note: the SVN server and WEB are on the same server. If the configuration is separated, the configuration needs to be changed. The above configuration is for reference, but the method is the same as the steps.

Test access

First, we update the current code under the WEB site directory, which is equivalent to making a "copy" of the SVN code directory in the WEB directory.

Svnco svn://192.168.4.254:/doc/test / svncode/test/-username=test01-password=test123

[root@centos test] # pwd

/ usr/local/apache-tomcat-8.5.9/webapps/test

[root@centos test] # ll

Total 216

-rw-r--r-- 1 root root 1241 Jun 11 04:06 index.html

-rw-r--r-- 1 root root 142943 Jun 10 20:12 server.jpg

-rw-r--r-- 1 root root 68533 Jun 10 20:12 u.jpg

Open a browser to test access

Next, simulate the development and modify the relevant code files, and resubmit the code to the SVN version library

Reopen the browser to test whether the access page is updated?

The code is automatically updated to the WEB directory to complete

Thank you for reading this article carefully. I hope the article "how to configure the hooks function of SVN to update the code automatically" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report