title: Trying to loop through an array and pass each value into a gradle task
body: <p>I'm trying to do a series of things which should be quite simple, but are causing me a lot of pain. At a high level, I want to loop through an array and pass each value into a gradle task which should return an array of its own. I then want to use this array to set some Jenkins config.</p>
  
  <p>I have tried a number of ways of making this work, but here is my current set-up:</p>
  
  <pre><code>project.ext.currentItemEvaluated = "microservice-1"
  
  task getSnapshotDependencies {
      def item = currentItemEvaluated
      def snapshotDependencies = []
  
      //this does a load of stuff like looping through gradle dependencies,
      //which means this really needs to be a gradle task rather than a 
      //function etc. It eventually populates the snapshotDependencies array.
  
      return snapshotDependencies
  }
  
  jenkins {
      jobs {
          def items = getItems() //returns an array of projects to loop through
          items.each { item -&gt;
             "${item}-build" {
                  project.ext.currentItemEvaluated = item
                  def dependencies = project.getSnapshotDependencies
                  dsl {
                      configure configureLog()
                      //set some config here using the returned dependencies array
               }
           }
       }
  }
  </code></pre>
  
  <p>I can't really change how the jenkins block is set-up as it's already well matured, so I need to work within that structure if possible. </p>
  
  <p>I have tried numerous ways of trying to pass a variable into the task - here I am using a project variable. The problem seems to be that the task evaluates before the jenkins block, and I can't work out how to properly evaluate the task again with the newly set <code>currentItemEvaluated</code> variable.</p>
  
  <p>Any ideas on what else I can try?</p>