使用Jenkins实现CI/CD管道
我正在尝试使用kubernetes、Jenkins和我在本地服务器中的私有SVN代码库来实现CI/CD管道。当我观看实现管道的示例时,我只看到GitHub-Web钩子的使用。当提交到GitHub存储库时,使用web钩子触发。在我的开发场景中,我使用的是SVN存储库。所以在我之前的堆栈溢出讨论中,我发现在Jenkins中添加一个SVN插件。在这里,我感到怀疑使用Jenkins实现CI/CD管道,jenkins,Jenkins,我正在尝试使用kubernetes、Jenkins和我在本地服务器中的私有SVN代码库来实现CI/CD管道。当我观看实现管道的示例时,我只看到GitHub-Web钩子的使用。当提交到GitHub存储库时,使用web钩子触发。在我的开发场景中,我使用的是SVN存储库。所以在我之前的堆栈溢出讨论中,我发现在Jenkins中添加一个SVN插件。在这里,我感到怀疑 与使用GitHub的web钩子触发功能不同,我们可以使用SVN插件做什么?在Jenkins中是否有这样的配置:当提交到代码repo中时,构建
$REPOSITORY/hooks
目录中的post commit
文件中(参见下面的示例)$REPOSITORY/hooks
目录中的post commit
文件中:
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/subversion/${UUID}/notifyCommit?rev=$REV
他们还有一个更可靠的例子,考虑到了安全性:
#!/bin/sh
REPOS="$1"
REV="$2"
# No environment is passed to svn hook scripts; set paths to external tools explicitly:
WGET=/usr/bin/wget
SVNLOOK=/usr/bin/svnlook
# If your server requires authentication, it is recommended that you set up a .netrc file to store your username and password
# Better yet, since Jenkins v. 1.426, use the generated API Token in place of the password
# See https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients
# Since no environment is passed to hook scripts, you need to set $HOME (where your .netrc lives)
# By convention, this should be the home dir of whichever user is running the svn process (i.e. apache)
HOME=/var/www/
UUID=`$SVNLOOK uuid $REPOS`
NOTIFY_URL="subversion/${UUID}/notifyCommit?rev=${REV}"
CRUMB_ISSUER_URL='crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
function notifyCI {
# URL to Hudson/Jenkins server application (with protocol, hostname, port and deployment descriptor if needed)
CISERVER=$1
# Check if "[X] Prevent Cross Site Request Forgery exploits" is activated
# so we can present a valid crumb or a proper header
HEADER="Content-Type:text/plain;charset=UTF-8"
CRUMB=`$WGET --auth-no-challenge --output-document - ${CISERVER}/${CRUMB_ISSUER_URL}`
if [ "$CRUMB" != "" ]; then HEADER=$CRUMB; fi
$WGET \
--auth-no-challenge \
--header $HEADER \
--post-data "`$SVNLOOK changed --revision $REV $REPOS`" \
--output-document "-"\
--timeout=2 \
${CISERVER}/${NOTIFY_URL}
}
# The code above was placed in a function so you can easily notify multiple Jenkins/Hudson servers:
notifyCI "http://myPC.company.local:8080"
notifyCI "http://jenkins.company.com:8080/jenkins"
现在我正在实现post-commit钩子,并面临关于post-commit文件配置的问题。我探索了你的答案并实现了同样的方法。我得到了链接。你能检查一下这个吗?