SVN鉤子hooks

來源:互聯網
上載者:User

標籤:smarty   hook   目錄   repos   屬性   改變   永久   更新   time   

簡述

由於安全原因,Subversion版本庫在一個空環境中執行鉤子指令碼-->就是沒有任何環境變數,甚至沒有$PATH或%PATH%。注意必須在你的鉤子中設定好環境變數或為你的程式指定好絕對路徑。

預設情況下,SVN版本庫鉤子的目錄中包含各種版本庫鉤子模板

[[email protected] hooks]# ll /svn/HLink/hooks/總用量 36-rw-r--r-- 1 root root 1977 12月 19 2016 post-commit.tmpl-rw-r--r-- 1 root root 1638 12月 19 2016 post-lock.tmpl-rw-r--r-- 1 root root 2289 12月 19 2016 post-revprop-change.tmpl-rw-r--r-- 1 root root 1567 12月 19 2016 post-unlock.tmpl-rw-r--r-- 1 root root 3426 12月 19 2016 pre-commit.tmpl-rw-r--r-- 1 root root 2410 12月 19 2016 pre-lock.tmpl-rw-r--r-- 1 root root 2786 12月 19 2016 pre-revprop-change.tmpl-rw-r--r-- 1 root root 2100 12月 19 2016 pre-unlock.tmpl-rw-r--r-- 1 root root 2780 12月 19 2016 start-commit.tmpl

 

start-commit  事務建立之前。

傳給 hook 的 參數:

-         參 數 1 , 程式碼程式庫路徑。

-         參 數 2 , 試圖提交的使用者名稱。

hook 的傳回值:非 0 則 終止。

一 般用途:判斷使用者是否有許可權進行提交 操作。

pre-commit  事務完成,但未提交。

-         參 數 1 , 程式碼程式庫路徑。

-         參 數 2 , 事務名。

hook 的傳回值:非 0 則 終止提交,操作復原。

一 般用途:對提交內容進行檢查。如要求 提交必須填寫提交資訊。

post-commit  事務提交完畢,新的修訂版被 建立。

傳給 hook 的 參數:

-         參 數 1 , 程式碼程式庫路徑。

-         參 數 2 , 剛建立的修訂版號。

hook 的傳回值被忽 略。

一 般用途:發送郵件通知,或備份代碼 庫。

pre-revprop-change  修改修訂版屬性(如提交時提 供的資訊 message )之前。

由於修訂版屬性一旦修改就會 永久的丟失,除非安裝這個事件的 hook ,subversion 的 用戶端不允許遠程修改修訂版屬性。

傳給 hook 的 參數:

-         參 數 1 , 程式碼程式庫路徑。

-         參 數 2 , 要修改的修訂版號。

-         參 數 3 , 操作使用者名稱。

-         要 修改的屬性。

hook 的傳回值:非 0 則 終止。

一 般用途:儲存修訂版屬性的改變記錄。

post-revprop-change  修訂版屬性值被修改之後。

如果沒有安裝 pre-revprop-change 的 hook , 這個事件的 hook 不會被執行。

傳給 hook 的 參數:

-         參 數 1 , 程式碼程式庫路徑。

-         參 數 2 , 要修改的修訂版號。

-         參 數 3 , 操作使用者名稱。

-         要 修改的屬性。

hook 的傳回值被忽 略。

一 般用途:發送郵件

實踐

因svn倉庫在伺服器2上, 伺服器3是測試伺服器, 鉤子要遠程執行更新指令碼.所以先做ssh免密認證

伺服器2上 產生秘鑰對   ssh-keygen   , ssh-copy-id 把公開金鑰發給伺服器3 

編輯鉤子指令碼

[[email protected] hooks]# vim post-commit

#!/bin/bashexport LANG=en_US.UTF-8REPOS="$1"TXN="$2"datelog=`date +%Y%m%d`datetime=`date +%Y-%m-%d-%T-%A`# Make sure that the log message contains some text./bin/echo $REPOS $TXN $datetime >>/tmp/svn-hcloud-$datelog.log || exit 1ssh 192.168.0.3 "sh /srv/uphcloud.sh"# Check that the author of this commit has the rights to perform# the commit on the files and directories being modified.# commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1 # All checks passed, so allow the commit.exit 0

 

[[email protected] ~]# cat /srv/uphcloud.sh #!/bin/bashtype svnif [ $? != 0 ];then    echo "need install subversion first"    exitficd /srv[ ! -e /srv/hcloud ]&& mkdir -p /srv/hcloud;cd /srv/hcloudecho `pwd` >>/srv/herror.logecho `date` >>/srv/herror.log# BScloud echo "hcloud" >>/srv/herror.log#if [ ! -e /srv/hcloud ]; thenif [ ! -e /srv/hcloud/web ]; then    /usr/bin/svn co --no-auth-cache svn://192.168.0.2/hcloud/web --username svn帳號 --password 密碼 2>&1 >>/srv/herror.logelse    #cd /srv/hcloud/    cd /srv/hcloud/web    /usr/bin/svn update --no-auth-cache --username svn帳號 --password 密碼 2>&1 >>/srv/herror.log    cd /srvficp -uraf /srv/hcloud/web/* /data/web/hcloud/web/cd /data/web/chown -R nginx:nginx hcloud/chmod -R 777 /data/web/hcloud/web/web_code/smarty/templates_c

 

SVN鉤子hooks

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.