简体   繁体   English

Jenkins管道:从其他代理轮询SCM

[英]Jenkins pipeline: poll SCM from a different agent

I'm working on a Jenkins pipeline (Windows master) that must run on a Linux slave agent/node. 我正在研究必须在Linux从属代理/节点上运行的Jenkins管道(Windows主管道)。 I would like to kick the job off based on polling the git repository, but the repository is only visible from the slave node due to firewall configuration. 我想基于轮询git存储库开始这项工作,但是由于防火墙配置,该存储库仅在从属节点中可见。

The pipeline uses the "agent{node{label 'xxx'}}" declaration to run on the correct slave. 管道使用“ agent {node {label'xxx'}}”声明在正确的从属服务器上运行。 However, all attempts to poll the repo seem to come from the master, as the polling log shows. 但是,轮询日志显示,所有轮询回购协议的尝试似乎都来自主数据库。 Is there a way to poll the git repo from the slave node? 有没有办法从从节点轮询git repo? A change to the firewall configuration is possible, but due to our IT security organization, not expedient. 可以更改防火墙配置,但是由于我们的IT安全组织,所以不方便。

Since no better options have been immediately forthcoming, here's my workaround in detail. 由于没有更好的选择可立即出现,因此,这是我的详细解决方法。 This "GitPoller" job is configured to run at 10-minute intervals. 该“ GitPoller”作业被配置为每隔10分钟运行一次。 It runs on the target agent (which has visibility to the git SCM server) and does a git checkout and checks for new change sets. 它在目标代理(对git SCM服务器具有可见性)上运行,并执行git checkout并检查新的变更集。 If any change sets are found, then it runs the actual build job. 如果找到任何变更集,则它将运行实际的构建作业。

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'
                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM