我已经设置了一个版本控制系统(Subversion),开发人员将使用它来提交和更新他们的代码(假设它的地址是https://server/svn/project
)。只有经过身份验证的用户才能访问项目的SVN。
另一方面,我已经安装了Hudson作为项目的持续集成服务器(项目地址为server:8080/job/project
)。
我想实现以下目标:
我为Hudson用户设置了基于矩阵的授权,因为我不想对任何人开放。
我已经看到了post-commit
钩子的一些建议,但直到现在它们都没有工作。
有人可以建议对这两个问题做些什么吗?具体步骤将不胜感激。
答案 0 :(得分:7)
根据"Building a software project # Builds by changes in Subversion/CVS",Hudson需要轮询您的SVN回购以检测更改并触发构建。
但是,这可以在SVN的每次提交时启动,例如in this thread 官方脚本位于Subversion Plugin页面。
REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
/usr/bin/wget \
--header "Content-Type:text/plain;charset=UTF-8" \
--post-data "`svnlook changed --revision $REV $REPOS`" \
--output-document "-" \
--timeout=2 \
http://server/hudson/subversion/${UUID}/notifyCommit?rev=$REV
但是它被指定:
为此,您的Hudson必须允许对系统进行匿名读取访问。
如果您对Hudson的访问控制更具限制性,您可能需要指定用户名和密码,具体取决于您的身份验证配置方式。
答案 1 :(得分:4)
要在SVN中提交时触发构建,您必须(1)将hudson作业设置为远程构建,(2)创建SVN钩子...
第一部分相当简单......使钩子转到/ var / lib / svn //钩子并将post-commit.tmpl重命名为post-commit 在那里你可以做类似
的事情#!/bin/bash
# Este script comprueba si se han hecho cambios en un directorio concreto,
# y en tal caso lanza una build en Jenkins
REPOS="$1"
REV="$2"
JENKINS_JOB="$3"
JENKINS_USER=admin
JENKINS_PASSWORD=****
JENKINS_HOST=<hostname>
if [ -n $(svnlook dirs-changed $REPOS --revision $REV | fgrep "tags\/") ];then
wget --quiet --auth-no-challenge --no-check-certificate --http-user=$JENKINS_USER --http-password=$JENKINS_PASSWORD http://$JENKINS_HOST/job/$JENKINS_JOB/build?token=TOKEN
fi
exit 0
看看这篇文章http://blogsyntagma.blogspot.com.ar/2012/04/hook-de-subversion-para-ejecutar-un-job.html(用西班牙语)
答案 2 :(得分:1)
以下是必需的步骤:
我建议通过电子邮件发送给所有开发人员,以便他们收到通知说构建不稳定,而不仅仅是罪魁祸首。这不仅提供了更多的可见性,而且还会激发罪魁祸首立即解决问题或以其他方式接受来自其他开发人员的责骂。相信我,这是有效的。
答案 3 :(得分:0)
这是我提交SVN存储库后让Jenkins 2.157开始构建的方式。
使用Jenkins的网络界面,转到Manage Jenkins
-> Configure Global Security
并选中Allow anonymous read access
:
如果您跳过此步骤,则尝试使用HTTP请求触发构建时会收到以下响应(在第三步中进行了描述):
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->
仍然在Jenkins的Web界面中,转到构建作业并定义您要使用脚本来触发构建(下一步将是SVN commit钩子):
post-commit
钩子最后,转到存储库的hooks
目录并添加名为post-commit
的shell脚本(名称很重要,否则SVN在提交后将不会执行它):
#!/bin/sh
# Name of the Jenkins build job
yourJob="your_job"
# You defined this in Jenkins' build job
build_token="yourSecretToken"
jenkins_address_with_port="localhost:8090"
curl $jenkins_address_with_port/job/$yourJob/build?token="$build_token"
使脚本可执行:chmod +x post-commit
。
这是post-commit
的扩展版本,用于记录有关提交的数据,例如提交的作者。
#!/bin/sh
# The path to this repository
repo_path="$1"
# The number of the revision just committed
rev="$2"
# The name of the transaction that has become rev
transaction_name="$3"
# See http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.author.html
commit_author="$(svnlook author --revision $rev $repo_path)"
# The UUID of the repository, something like e3b3abdb-82c2-419e-a100-60b1d0727d12
repo_uuid=$(svnlook uuid $repo_path)
# Which files were changed, added, or deleted. For example:
# U src/main/java/com/bullbytes/MyProgram.java
what_has_changed=$(svnlook changed --revision $rev $repo_path)
log_file=/tmp/post_commit.log
echo "Post-commit hook of revision $rev committed by $commit_author to repo at $repo_path with ID $repo_uuid was run on $(date). Transaction name: $transaction_name. User $(whoami) executed this script. This has changed: $what_has_changed" >> $log_file
# Name of the Jenkins build job
yourJob="your_job"
# You defined this in Jenkins' build job
build_token="yourSecretToken"
jenkins_address_with_port="localhost:8090"
curl $jenkins_address_with_port/job/$yourJob/build?token="$build_token"
要了解有关提交挂钩的更多信息,请前往docs。