简体   繁体   中英

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. 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.

The pipeline uses the "agent{node{label 'xxx'}}" declaration to run on the correct slave. 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? A change to the firewall configuration is possible, but due to our IT security organization, not expedient.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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