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 added a comment -

            Apologies, please disregard this whole request. There were agent restrictions in place that caused this.

            mwisnicki Marcin added a comment - Apologies, please disregard this whole request. There were agent restrictions in place that caused this.
            mwisnicki Marcin added a comment -

            Actually I've tried refactoring to sequential stages which explicitly supports this scenario and ended up with the same issue.

            Still waiting to schedule task 

            and then long list of agents but none of them matching.

            mwisnicki Marcin added a comment - Actually I've tried refactoring to sequential stages which explicitly supports this scenario and ended up with the same issue. Still waiting to schedule task and then long list of agents but none of them matching.
            mwisnicki Marcin added a comment -

            Also this limitation of declarative pipeline is quite annoying.

            mwisnicki Marcin added a comment - Also this limitation of declarative pipeline is quite annoying.
            mwisnicki Marcin added a comment -

            Looks like this is JENKINS-51891 which was open for a while. Would be nice if at least documentation was updated if generating runtime error is too hard.

            mwisnicki Marcin added a comment - Looks like this is  JENKINS-51891 which was open for a while. Would be nice if at least documentation was updated if generating runtime error is too hard.

            People

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

              Dates

                Created:
                Updated:
                Resolved: