Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66442

Unable to override agent per stage

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not A Defect
    • core, pipeline
    • None
    • Jenkins: 2.289.2

    Description

      I have a pipeline with top-level agent but want to override single stage to run on different agent:

      pipeline {
        agent { label 'agent-pool' }
        stages {
          stage('checkout') {}
          stage('prepare data') {
            agent { label 'special-agent' }
            steps {
              // do what's needed
              stash name:'data', include: 'data/**'
          }
          stage('build') {
            unstash 'data'
          }
          // more stages that should execute on the same agent from agent-pool
          stage('deploy') {}
        }
      } 

       

      The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

      My reading of https://www.jenkins.io/doc/book/pipeline/syntax/#agent and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:

      'agent-1': doesn't have label 'special-agent'
      'agent-2': doesn't have label 'special-agent'
      # etc...
      # infinite spinner 

      I've found one post on stackoverflow claiming this is actually not supported: https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354 however this goes against referenced documentation.

      Attachments

        Issue Links

          Activity

            mwisnicki Marcin created issue -
            mwisnicki Marcin made changes -
            Field Original Value New Value
            Description I have a pipeline with top-level agent but want to override single step to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            mwisnicki Marcin made changes -
            Description I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            mwisnicki Marcin made changes -
            Description I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.

             

            Jenkins: 2.289.2
            mwisnicki Marcin made changes -
            Component/s core [ 15593 ]
            mwisnicki Marcin made changes -
            Description I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.

             

            Jenkins: 2.289.2
            I have a pipeline with top-level agent but want to override single stage to run on different agent:
            {code:java}
            pipeline {
              agent { label 'agent-pool' }
              stages {
                stage('checkout') {}
                stage('prepare data') {
                  agent { label 'special-agent' }
                  steps {
                    // do what's needed
                    stash name:'data', include: 'data/**'
                }
                stage('build') {
                  unstash 'data'
                }
                // more stages that should execute on the same agent from agent-pool
                stage('deploy') {}
              }
            } {code}
             

            The idea is there are a lot of stages that execute on single node but there is one special stage that has to execute on special agent that is not in the pool (and move results around with stash).

            My reading of [https://www.jenkins.io/doc/book/pipeline/syntax/#agent] and JENKINS-37779 is that this should just work however when I tried this, Jenkins attempted to use just about any agent except the one matching special-agent:
            {code:java}
            'agent-1': doesn't have label 'special-agent'
            'agent-2': doesn't have label 'special-agent'
            # etc...
            # infinite spinner {code}
            I've found one post on stackoverflow claiming this is actually not supported: [https://stackoverflow.com/questions/46630168/in-a-declarative-jenkins-pipeline-can-i-set-the-agent-label-dynamically#comment116214727_46631354] however this goes against referenced documentation.
            Environment Jenkins: 2.289.2
            mwisnicki Marcin made changes -
            Resolution Not A Defect [ 7 ]
            Status Open [ 1 ] Closed [ 6 ]
            mwisnicki Marcin made changes -
            Link This issue is related to JENKINS-66447 [ JENKINS-66447 ]

            People

              Unassigned Unassigned
              mwisnicki Marcin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: