我試圖編寫一個svn post-commit腳本,目的是意識到只要有一個開發人員提交到svn repository,它就會觸發jenkins自動構建和部署該項目。如何使用svn post-commit觸發jenkins構建?
我跟着指示https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin,和我的post-commit就像
#!/bin/sh
#
# Jenkins SVN Build trigger script by Wessel de Roode Aug' 2011
#
# Please adjust
SERVER=localhost
PORT=8080
WGET=/usr/bin/wget
SVNLOOK=/usr/bin/svnlook
# Don't change below this point
###############################
REPOS="$1"
REV="$2"
UUID=`$SVNLOOK uuid $REPOS`
echo "--------------------------------">>${REPOS}/post-commit.log
#
# Check if "[X] Prevent Cross Site Request Forgery exploits" is activated
# so we can present a valid crum or a proper header
BREAD_URL='http://'${SERVER}:${PORT}'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
CRUMP=`$WGET --append-output=${REPOS}/post-commit.log --output-document -${BREAD_URL}`
if [ "$CRUMP" == "" ]
then
HEADER="Content-Type:text/plain;charset=UTF-8"
else
HEADER=$CRUMP
fi
$WGET \
--http-user=JENKINS_USER --http-password=JENKINS_PW \
--header ${HEADER} \
--post-data "`$SVNLOOK changed --revision $REV $REPOS`" \
--append-output=${REPOS}/post-commit.log \
--output-document "-"\
--timeout=2 \
http://${SERVER}:${PORT}/jenkins/subversion/${UUID}/notifyCommit?rev=$REV\
# Uncomment line below for debug
echo $(date) HEADER=${HEADER} REPOS=$REPOS REV=$REV UUID=${UUID} http://${SERVER}:${PORT}/subversion/${UUID}/notifyCommit?rev=$REV >>${REPOS}/post-commit.log
當我承諾的東西從SVN客戶端,該日誌如下:
--2015-04-03 21:01:20-- http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 404 Not Found
2015-04-03 21:01:20 ERROR 404: Not Found.
Fri Apr 3 21:01:20 KST 2015 HEADER=Content-Type:text/plain;charset=UTF-8 REPOS=/home/share/svn/myblog REV=30 UUID=d6922f4b-358e-4015-8fd3-a25217326040 http://localhost:8080/subversion/d6922f4b-358e-4015-8fd3-a25217326040/notifyCommit?rev=30
--2015-04-03 21:01:20-- http://localhost:8080/jenkins/subversion/d6922f4b-358e-4015-8fd3-a25217326040/notifyCommit?rev=30
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 403 Forbidden
2015-04-03 21:01:20 ERROR 403: Forbidden.
對於404不發現錯誤,我檢查了Jenkins中的Global Security配置。
我不知道爲什麼會發生錯誤。
對於403 Forbidden錯誤,提到前面的屏幕截圖,我提供了一個用戶/密碼JENKINS_USER/JENKINS_PW(即使他們說我將使用API Token而不是純文本的密碼),爲什麼是它被禁止?
任何人都可以幫我嗎?任何建議都會感恩。
是'localhost'正確嗎?也就是說,你的SVN服務器和Jenkins服務器是同一臺機器嗎? – 2015-04-03 12:27:22
@PatrickQuirk感謝您的關注。是的,他們在同一臺機器上運行,我正在爲了學習目的而這樣做。 – sincosmos 2015-04-03 13:04:50