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

Dynamic node names for parallel branches in Jenkins pipeline

XMLWordPrintable

      I wonder how to accomplish dynamic node names or passing any variables to branches in general?

      How to pass variable nodeName into closure ? Please consider following code:

      def getBranches(def config){
          def branches = [:]
          for (node in config){
              def nodeName = node.get('node')
              def udid = node.get('udid')
              echo "node: ${nodeName}"
              echo "udid: ${udid}"
      
              branches[nodeName] = { 
                  node(nodeName){
                      echo "1"
                      echo "${udid}"
                  }
              }
          }
          return branches
      }
      
      stage('My awesome parallel jobs stage'){
          node {
              def config = getConfig()
              def branches = getBranches(config)
              parallel branches
          }
      }
      

            Unassigned Unassigned
            danilz Danil Zvyagintsev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: