Run multiple agents in a single stage simultaneously in Declarative Jenkins Pipeline

Viewed 118

I'm trying to copy some artifacts simultaneously inside of the slave agents. I've 10 slave agents. But, I'm unable to copy the artifacts simultaneously in all the slave agents in a feasible manner. What I've done so far is, running all the slave agents in parallel, inside of different stages. Like this:

stage ('Copy Artifacts') {
        parallel {
        stage('Agent-1') {
            agent {
                label "BS-QA-Agent-7"
            }
            steps {
                copyArtifacts projectName: "${BUILDPROJECT}", selector: lastSuccessful(), target: 'artifacts'
            }
        }
        stage('Agent-2') {
            agent {
                label "BS-QA-Agent-6"
            }
            steps {
                copyArtifacts projectName: "${BUILDPROJECT}", selector: lastSuccessful(), target: 'artifacts'
            }
        }
        }
   } 

It is working as I expected. But, in this way, for 10 agents, I need 10 parallel stages; which I don't want to.

Another way I found on the Internet is to use '&&' operator. Like this:

pipeline {
    agent {
        label 'BS-QA-Agent-7 && BS-QA-Agent-6'
    }
    stage {
        steps {
                    copyArtifacts projectName: "${BUILDPROJECT}", selector: lastSuccessful(), target: 'artifacts'
              }
    }
}

But, it throws the error:

There are no nodes with the label ‘BS-QA-Agent-6&&BS-QA-Agent-7’

I couldn't find any more feasible solution. Can someone give me any idea, how can I overcome this issue? I'm entirely new in Jenkins.

0 Answers
Related