'Is it possible to create a Jenkins artifact on a agent/worker node?

In a pipeline style script, if I want to store a file as a Jenkins artifact, I use:

archiveArtifacts artifacts: 'path/goes/here'

This works fine when the file is on the same node that Jenkins itself is running on (let's call this the master node). If I have a file that gets generated on a worker node and I want to store it as a Jenkins artifact, I figured I could do the same thing. Here is a sample pipeline:

timeout(time: 4, unit: 'HOURS') {

    node('master') {
        archiveArtifacts artifacts: '1.txt'
    }
        
    node("worker") {
        archiveArtifacts artifacts: '2.txt'
    }

}   

This script successfully artifacts 1.txt but hangs when I try to artifact 2.txt. Is this expected behavior? If not, what is the most common way people deal with artifacting files NOT on the master Jenkins node?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source