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 update projects automatically with SVN hooks

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to update the project automatically with the SVN hook". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to update the project automatically with the SVN hook".

Update with post-commit

1.SVN server address: 192.168.31.33

2.web server address: 192.168.31.34

3.SVN version Library address: / home/svn/qxy

4.web project address: / home/wwwroot/qxy

5. Since SVN and web are not on the same server, ssh login is involved and keyless login needs to be set up.

Implementation principle of personal svn synchronization

1. The developer's local computer is sent to the SVN server via the SVN Commit version.

The 2.SVN server post-commit detected a version change and logged in to the web server to perform the svn update operation through ssh according to the defined settings

3. I need to record some information, so I use ssh login to execute a specific script for update operation

The hook location is located in the SVN server / home/svn/qxy/hooks directory, and common hooks are provided by default:

[root@docker_server hooks] lltotal 36 RW Sep-1 root root 1977 Sep 1 16:49 post-commit.tmpl-rw-r--r-- 1 root root 1638 Sep 1 16:49 post-lock.tmpl-rw-r--r-- 1 root root 2289 Sep 1 16:49 post-revprop-change.tmpl-rw-r--r-- 1 root root 1567 Sep 1 16:49 post-unlock.tmpl-rw-r--r-- 1 root root 3426 Sep 1 16:49 pre-commit.tmpl-rw-r--r-- 1 root root 2434 Sep 1 16:49 pre-lock.tmpl-rw-r--r-- 1 root root 2786 Sep 1 16:49 pre-revprop-change.tmpl-rw-r--r-- 1 root root 2122 Sep 1 16:49 pre-unlock.tmpl-rw-r--r-- 1 root root 2780 Sep 1 16:49 start-commit.tmpl

Authorize SVN server face key to log in to web server

1. Generate a key file on the SVN server:

Ssh-keygen-t rsa

You can enter continuously. The generated file is located under / root/.ssh/. You need ls-a command to view it.

two。 Copy the key file to the web server:

Ssh-copy-id-I / root/.ssh/id_rsa.pub root@192.168.31.34

This operation requires entering the root password of the web server

3. After the copy is completed, a known_hosts file will be generated under / root/.ssh, which records the authorization information (encrypted).

Edit the post-commit file

Cp post-commit.tmpl post-commitvim poster poster exec binapor bashREPOS = "$1" REV= "$2" LOGFILE=/var/log/svn.logexec 1 > > & 1export LC_CTYPE= "en_US.UTF-8" export LC_ALL=SVNLOOK=/usr/bin/svnlookTIME=$ (date "+% Y-%m-%d% H:%M:%S") AUTHOR=$ ($SVNLOOK author-r $REV "$REPOS") CHANGEDDIRS=$ ($SVNLOOK dirs-changed $REPOS) MESSAGE=$ ($SVNLOOK log-r $REV "$REPOS") function myecho () {echo "$TIME"$*"} myecho "*"myecho" submitted version: $REV author: $AUTHOR "myecho" submission remarks: $MESSAGE "myecho" modified directory: $(echo $CHANGEDDIRS | tr'\ n'' ') "ssh root@192.168.31.34" / home/svnup.sh "> / dev/null

Increase script execution permissions

Chmod 744 post-commit

Create a matching script on the web server

Vim / home/svnup.sh #! / bin/bashlogfile=/var/log/svnup.logecho "--> > $logfileecho $(date +"% y-%m-%d% H:%M:%S ") > > $logfilesvn update / home/wwwroot/qxy > > $logfileecho"-- > > $logfile

Script testing

Run hook sh post-commit directly on the SVN server. If everything is normal, log information will be generated in the corresponding two log files. Although there is no version update on the web server, it will also generate updated records.

Develop a computer to push the version to the SVN server for testing, if there is an error, there will be post-commit-related prompts, generally a command problem in the hook, detailed error can be.

This solution is actually very cumbersome, and requires the web server to be able to log in to root. In addition, if there are different projects under a version library, it is impossible to determine which project to update, which will be further improved.

Thank you for your reading, the above is the content of "how to update the project automatically with SVN hook". After the study of this article, I believe you have a deeper understanding of how to use SVN hook to automatically update the project, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Network Security

Wechat

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

12
Report