title: Combining multiple collectEntries in Groovy and Jenkins Pipeline
body: <p>I am trying to use multiple <code>collectEntries</code> in series in my Groovy script. Its better to see the code, right now I've got:</p>
  
  <pre><code>stage('Test') {
              // Reading content of the file
              def portsFileContent = readFile 'UsedPorts.txt'
  
              // Split the file by next line
              def ports = portsFileContent.split('\n')
  
              def steps = ports.collectEntries { port -&gt;
                  ["UI Test on port $port", {
                      sh "#!/bin/bash -lx \n startServerWithDifferentPort --params=port=$port"
                  }]
              }
              parallel steps
          }
  </code></pre>
  
  <p>In the file "UsedPorts.txt" are different ports seperate by line break like:</p>
  
  <pre><code>4723
  4733
  4743
  </code></pre>
  
  <p>So this numbers getting stored in the variable <code>ports</code> and this variable is then used to start an instance of an server for each port. So in this case it would then start 3 different serverinstance by this command:</p>
  
  <pre><code>def steps = ports.collectEntries { port -&gt;
                  ["UI Test on port $port", {
                      sh "#!/bin/bash -lx \n startServerWithDifferentPort --params=port=$port"
                  }]
              }
              parallel steps
  </code></pre>
  
  <p>Because of <code>parallel steps</code> its starting 3 instance of the server simultaneously with different ports.</p>
  
  <p>Thats working fine, but I  have another file and need to do the same again. So in my second file there are entries like:</p>
  
  <pre><code>name1
  name2
  name3
  </code></pre>
  
  <p>I created again a variable where I store my 3 entries:</p>
  
  <pre><code>def anotherFile = readFile 'Names.txt'
  def names = anotherFile.split('\n')
  </code></pre>
  
  <p>This is what I tried:</p>
  
  <pre><code>stage('Test') {
              // Reading content of the file
              def portsFileContent = readFile 'UsedPorts.txt'
  
              // Split the file by next line
              def ports = portsFileContent.split('\n')
  
              // Do the same again
              def anotherFile = readFile 'Names.txt'
              def names = anotherFile.split('\n')
  
              def steps = ports.collectEntries, names.collectEntries { port, name -&gt;
                  ["UI Test on $name", {
                      sh "#!/bin/bash -lx \n someMoreShellStuff --params=port=$port"
                  }]
              }
              parallel steps
          }
  </code></pre>
  
  <p>But I can not seperate my second <code>collectEntries</code> by comma, because it gives me a syntax error. And now my problem is, how I can use this variable in the same command. Is it even possible?</p>
  
  <p>Thanks</p>
  
  <p><strong>Update #1</strong></p>
  
  <p>After using the answer of Szymon Stepniak my new code looks like this:</p>
  
  <pre><code>stage('Test') {
              // Reading content of the file
              def portsFileContent = readFile 'AppiumUsedPorts.txt'
  
              // Split the file by next line
              def ports = portsFileContent.split('\n')
  
              // Getting device IDs to get properties of device
              def deviceIDFileContent = readFile 'DeviceIDs.txt'
              def deviceIDs = deviceIDFileContent.split('\n')
  
              // Define port and id as an pair
              def pairs = (0..Math.min(ports.size(), deviceIDs.size())).collect { i -&gt; [id: deviceIDs[i], port: ports[i]] }
  
              def steps = pairs.collectEntries { pair -&gt;
                  ["UI Test on ${pair.id}", {
                      sh "echo 'Running test with port ${pair.port}'"
                  }]
              }
              parallel steps
          }
  </code></pre>
  
  <p>This is causing the error <code>java.lang.ArrayIndexOutOfBoundsException</code></p>
  
  <p><strong>Update #2</strong></p>
  
  <p>Content of <code>AppiumUsedPorts.txt</code>:</p>
  
  <pre><code>4723
  4733
  </code></pre>
  
  <p>Content of <code>DeviceIDs.txt</code></p>
  
  <pre><code>5353352c
  G000KU0663550R92
  </code></pre>