【问题标题】:Jenkins pipeline: poll SCM from a different agentJenkins 管道:从不同的代理轮询 SCM
【发布时间】:2018-04-10 21:17:08
【问题描述】:

我正在开发一个必须在 Linux 从代理/节点上运行的 Jenkins 管道(Windows 主机)。我想基于轮询 git 存储库来启动这项工作,但由于防火墙配置,该存储库仅从从节点可见。

管道使用“agent{node{label 'xxx'}}”声明在正确的从站上运行。但是,轮询日志显示,所有轮询 repo 的尝试似乎都来自 master。有没有办法从从节点轮询 git repo?更改防火墙配置是可能的,但由于我们的 IT 安全组织,这不是权宜之计。

【问题讨论】:

  • 感谢您的参考,但我认为这无关紧要。不是我想以编程方式停止 SCM 轮询,而是我想在从站而不是主站上发生。
  • 我的解决方法:我设置了一个“poller”管道,定期在从机上运行一个阶段,以检查来自 git 的代码并检查 currentBuild.changeSets 以确定是否有任何更改。如果不是,则轮询作业失败。如果有更改,它将运行实际的管道作业。这意味着虽然轮询作业经常处于失败状态,但构建作业本身准确地反映了构建状态。然后我将轮询作业隐藏在一个文件夹中,项目中的任何人都不会在不查找的情况下看到它。
  • 有趣:如果没有人提供更好的选择,您可以将其发布为答案,甚至接受它。

标签: git jenkins-pipeline


【解决方案1】:

由于没有立即出现更好的选择,这里详细介绍了我的解决方法。此“GitPoller”作业配置为每 10 分钟运行一次。它在目标代理(对 git SCM 服务器具有可见性)上运行,并执行 git checkout 并检查新的更改集。如果找到任何更改集,则它会运行实际的构建作业。

pipeline {
    agent {
        node {
            label 'xyzzy' /* run on the firewalled machine */
        }
    }

    /* Declare the pipeline stages */
    stages {
        /* The "ScmFetch" stage fetches the baseline from git */
        stage('ScmFetch') {
            steps {
                echo 'Fetching from SCM...'

                /* Fetch the baseline from git */
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'blah-blah-blah']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'blah-blah-blah', url: 'url-of-git-repo']]])

                script {
                    if (currentBuild.changeSets.size() > 0) {
                        echo 'Found ' + currentBuild.changeSets.size() + ' change sets'
                        build 'real-build-job'
                    }
                    else {
                        echo 'Found no change sets'
                    }
                }                
            }

            post {
                failure {
                    echo 'FAILED in stage ScmFetch'
                }
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    相关资源
    最近更新 更多