【问题标题】:Jenkins Pipeline : How to poll specific branch in pipelineJenkins Pipeline:如何轮询管道中的特定分支
【发布时间】:2020-08-19 20:59:36
【问题描述】:

我正在开发 Jenkins,我正在定义一个管道。在管道中,我有一个代码构建阶段,它将为我编译项目。我需要为特定分支(开发)轮询 SCM。我无法弄清楚如何使用轮询来做到这一点。我无法使用 webhook,因为我们的 Jenkins 实例位于公司网络后面,无法通过 github 访问。如果从Jenkins打开连接,那么是的,github可以说话。

我在构建触发器中没有看到任何分支选项。我在管道中遗漏了什么吗?

所以这些是构建触发器。我推动了发展,但民意调查日志显示没有推动任何事情。我如何轮询开发?谢谢。

在管道脚本中,我还添加了轮询机制,但没有运气:

   stage('Preparation') {
            git (
              poll: true,
              branch: 'origin/develop',
              credentialsId: 'ID',
              url: 'https://github.com/company/reponame.git'
            )
        }

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    你的jenkinsfile应该是这样的

    pipeline {
    
    agent any
    
    triggers {
      cron('*/30 * * * *')  <-----This will run every 30 min and will pull
    }
    
    stages {
    
      stage('Git Checkout') {
        steps {
          checkout([$class: 'GitSCM',
          branches: [[name: "*/yourbranchname"]],   <----This branch
          doGenerateSubmoduleConfigurations: false,
          submoduleCfg: [],
          userRemoteConfigs: [
            [credentialsId: "ID",
              url: "yourgitrepo url"
            ]
          ]
        ])
      }
     }
    }
    

    【讨论】:

    • 非常感谢您的回答。我有 2 个问题:1)从触发器来看,只是 Jenkins 跟踪没有任何变化,并且不会进入下一阶段,或者它只是编译它。 2)结帐时,我只想检查develop是否有任何变化,然后触发codebuild。我已经有了 codebuild 脚本。它会作为 git checkout 的下一步吗?谢谢。
    • 我每 2 分钟做一次,然后拉。然后可以肯定的是,也推动了发展。没有什么不幸的。