【发布时间】:2015-04-03 12:18:28
【问题描述】:
我正在尝试编写一个 SVN 提交后脚本,目的是意识到,每当开发人员提交到 SVN 存储库时,它都会触发 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 Not Found error”,我检查了Jenkins中的全局安全配置:
我完全不知道为什么会发生错误。
对于“403 Forbidden error”,参考之前的屏幕截图,我提供了一个用户/密码,JENKINS_USER/JENKINS_PW(尽管他们说我将使用 API 令牌而不是明文密码),为什么会被禁止?
【问题讨论】:
-
localhost正确吗?即,您的 SVN 服务器和 Jenkins 服务器是同一台机器吗? -
@PatrickQuirk 感谢您的关注。是的,它们在同一台机器上运行,我这样做是为了学习。
标签: svn jenkins post-commit