Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Jenkins实现CI/CD管道_Jenkins - Fatal编程技术网

使用Jenkins实现CI/CD管道

使用Jenkins实现CI/CD管道,jenkins,Jenkins,我正在尝试使用kubernetes、Jenkins和我在本地服务器中的私有SVN代码库来实现CI/CD管道。当我观看实现管道的示例时,我只看到GitHub-Web钩子的使用。当提交到GitHub存储库时,使用web钩子触发。在我的开发场景中,我使用的是SVN存储库。所以在我之前的堆栈溢出讨论中,我发现在Jenkins中添加一个SVN插件。在这里,我感到怀疑 与使用GitHub的web钩子触发功能不同,我们可以使用SVN插件做什么?在Jenkins中是否有这样的配置:当提交到代码repo中时,构建

我正在尝试使用kubernetes、Jenkins和我在本地服务器中的私有SVN代码库来实现CI/CD管道。当我观看实现管道的示例时,我只看到GitHub-Web钩子的使用。当提交到GitHub存储库时,使用web钩子触发。在我的开发场景中,我使用的是SVN存储库。所以在我之前的堆栈溢出讨论中,我发现在Jenkins中添加一个SVN插件。在这里,我感到怀疑

  • 与使用GitHub的web钩子触发功能不同,我们可以使用SVN插件做什么?在Jenkins中是否有这样的配置:当提交到代码repo中时,构建项目、测试和部署?否则,我是否需要始终依赖jenkins的cron jobs
  • 就像在GitHub-WebHooks中一样,当提交变成代码repo时,我们可以在jenkins中配置哪个触发动作
  • 在使用post-commit钩子来获得所需的行为方面,有几个很好的例子。要回答您的问题,它看起来像:

  • 您可以将脚本添加到
    $REPOSITORY/hooks
    目录中的
    post commit
    文件中(参见下面的示例)
  • 您需要为Jenkins作业启用SCM轮询,但不管您给它什么样的时间表(您可以让它尽可能不频繁,如每月或每年)。如果禁用轮询,提交钩子将不会触发Jenkins构建
  • 我将提供他们的示例脚本,以防止链接腐烂;我只熟悉基于git的回购协议,所以我可能无法在这些脚本上提供太多帮助

    首先,这里是他们的基本示例,假设Jenkins配置为启用匿名读取访问和禁用CSRF(因此这根本不是一个非常安全的示例)。这将添加到
    $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文件配置的问题。我探索了你的答案并实现了同样的方法。我得到了链接。你能检查一下这个吗?