• +43 660 1453541
  • contact@germaniumhq.com

Copying Data to a Specific Jenkins Node During Stage


Copying Data to a Specific Jenkins Node During Stage

Let’s assume that during the build, you need to archive some data on a specific node. Yes, you could just rsync to it and post data, but if you already have a Jenkins agent running there, maybe there’s a simpler way.

jenkins specific node copy

Let’s assume that we have a build that can run on any node. How can copy data?

The easiest way is to tag the node, and simply stash/unstash the artifacts. What you can do in Jenkins you can select a node from the available pool of nodes by passing a tag to the node function: node('some-tag && some-other-tag'). This is how you can pick nodes where certain capabilities are required to run parts of the build.

So for us to get our data to our special agent, we’ll get it from any node using stash and have it available for unstashing in other places of our job execution, and call unstash on the special agent we want that data in.

stage('build') {
    node {
        // do the actual build
        // stash the data
        stash name: "special-data", includes: "output/*"
    }
}

stage('copy to special agent') {
    node('special-agent') {
        unstash "special-data"
        // further processing goes here
    }
}

That’s it! Simple, yet awesome!

PS: To add labels to your node, just go to: Manage Jenkins > Manage Nodes > select your node > Configure.