2015-04-03 237 views
0

我试图编写一个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配置。 Jenkins security setting

我不知道为什么会发生错误。

对于403 Forbidden错误,提到前面的屏幕截图,我提供了一个用户/密码JENKINS_USER/JENKINS_PW(即使他们说我将使用API​​ Token而不是纯文本的密码),为什么是它被禁止?

任何人都可以帮我吗?任何建议都会感恩。

+0

是'localhost'正确吗?也就是说,你的SVN服务器和Jenkins服务器是同一台机器吗? – 2015-04-03 12:27:22

+0

@PatrickQuirk感谢您的关注。是的,他们在同一台机器上运行,我正在为了学习目的而这样做。 – sincosmos 2015-04-03 13:04:50

回答

0

请与下面的方法试试,我希望它会工作...

您需要只需要一个插件,它是颠覆的插件。然后简单地进入jenkins-> job_name->构建触发器部分 - >(i)远程触发器构建(即从脚本)身份验证令牌:-Token_name

然后转到svn服务器的hooks目录,然后在下面的命令之后触发: - (c)chown -R www-data:www-data post-commit (d)vi提交后提示:所有提交后的提示:所有提交后的提交行应该被注释添加下面线在最后

语法(Linux用户): - 的/ usr /斌/卷曲http://username:[email protected]:8081/job/job_name/build?token=Token_name

语法(Windows用户): - C:/ curl_for_win /卷曲http://username:[email protected]:8081/job/job_name/build?token=Token_name