Checking out source on master node, then using it on worker

So I have a Jenkins controller, that is in a different network than the workers (ssh nodes).
The workers are behind a firewall and don’t have access to the source repository (git via git scm plugin).
Is there a way, I can check out the source from the controller node, then have the workers do jobs using that checkout?

This is something I do for “jenkins-dynamatrix” builds (e.g. used for NUT, where trawling through the hundreds of multi-platform build scenarios can take hours or even days, and force-pushed PR source branches may lose visibility of the original commit - so checkouts at start of build on an agent are not reliable).

For inspiration, see jenkins-dynamatrix/src/org/nut/dynamatrix/DynamatrixStash.groovy at 353e690199133de3f64b6cfdcaa210f33b88e602 · networkupstools/jenkins-dynamatrix · GitHub

1 Like

In a pipeline job you can have a first node step that runs on the controller and does the git checkout. Then you use the stash step that stores the sources, leave the controller node and start a new node step that uses the unstash step

node("built-in") {
  dir("src") {
    checkout scm
  }
  stash includes: 'src/**/*', name: 'sources'
}
node("linux") {
    unstash 'sources'
    // run the build
}

or with declarative you need at least 2 stages that each use an agent

pipeline {
  agent none
  ...
  stages {
    stage('checkout') {
      steps {
        dir("src") {
          checkout scm
        }
        stash includes: 'src/**/*', name: 'sources'    
      }

      agent {
        label 'built-in'
      }
    }

    stage('build') {
      steps {
        unstash 'sources'
        // run the build
      }

      agent {
        label 'linux'
      }
    }
  }
}
1 Like

That worked, thanks.

Now my only remaining concern is, how to get jenkins to stash and unstash hidden files (staring in a dot). includes: '**,.** does not seem to work.

Edit:
Nevermind, the solution is useDefaultExcludes: false