CopyPastor

Detecting plagiarism made easy.

Score: 0.821704626083374; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2022-10-12
by ycr

Original Post

Original - Posted on 2017-04-11
by mcalcote



            
Present in both answers; Present only in the new answer; Present only in the old answer;

As a workaround, instead of setting `any` you can set agent labels conditionally. Something like below.
``` def labels = "Windows"
if (params.RUN_WINDOWS && params.LINUX) { labels = "windows || linux" }
pipeline { agent any // main agent parameters { booleanParam( name: 'RUN_WINDOWS' ) booleanParam( name: 'RUN_LINUX' ) } stages { stage('Common step') { ... } stage("Test") { parallel { stage('Windows') { agent { label "${labelSelected}" } when { expression { return params.RUN_WINDOWS } } stages { stage('Test Windows') { ... } } } stage('Linux') { // no agent specified, so will use the main agent when { expression { return params.RUN_LINUX } } stages { stage('Test Linux') { ... } } } } post { ... } } } } ```
> EDIT: I misunderstood the question. This answer is only if you know > which specific agent you want to run for each stage.
If you need multiple agents you can declare `agent none` and then declare the agent at each stage.
https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents
From the docs:
pipeline { agent none stages { stage('Build') { agent any steps { checkout scm sh 'make' stash includes: '**/target/*.jar', name: 'app' } } stage('Test on Linux') { agent { label 'linux' } steps { unstash 'app' sh 'make check' } post { always { junit '**/target/*.xml' } } } stage('Test on Windows') { agent { label 'windows' } steps { unstash 'app' bat 'make check' } post { always { junit '**/target/*.xml' } } } } }


        
Present in both answers; Present only in the new answer; Present only in the old answer;