title: Jenkins: parallelize test execution
body: <p>I started using Jenkins in my project and  I am trying to parallelize my test suite (Rspec test cases) written in 4 files in Jenkins</p>
  
  <pre><code>spec/features/
  |-- test1.rb
  |-- test2.rb
  |-- test3.rb
  |-- test4.rb
  </code></pre>
  
  <p>We can run all test cases with below command, it will run all tests written in test1.rb ..test4.rb sequentially which will take around 1 hour.</p>
  
  <pre><code>script spec/features/
  </code></pre>
  
  <p>If you want to excute test cases from each test file we can run like </p>
  
  <pre><code>script spec/features/test1.rb
  </code></pre>
  
  <p>Now I want to parallelize these test cases which can reduce the run from 1hr to 15 mins, All these test cases can run in one machine in parallel</p>
  
  <p>I followed below approach in Jenkins</p>
  
  <p>1) Set a new job "Main_Test_job"</p>
  
  <p>2) </p>
  
  <pre><code>Selected "Trigger/Call builds on other projects"
  projects to build " Child_test_job"
  Build on same node
  Predefined Parameters TEST_UNIT=test1.rb
  Block until the triggered projects finish their builds ( Not selected this)
  </code></pre>
  
  <p>Add trigger ---></p>
  
  <pre><code>Selected "Trigger/Call builds on other projects"
  projects to build " Child_test_job"
  Build on same node
  Predefined Parameters TEST_UNIT=test2.rb
  Block until the triggered projects finish their builds ( Not selected this)
  </code></pre>
  
  <p>Add trigger ---></p>
  
  <pre><code>Selected "Trigger/Call builds on other projects"
  projects to build " Child_test_job"
  Build on same node
  Predefined Parameters TEST_UNIT=test3.rb
  Block until the triggered projects finish their builds ( Not selected this)
  </code></pre>
  
  <p>Add trigger ---></p>
  
  <pre><code>Selected "Trigger/Call builds on other projects"
  projects to build " Child_test_job"
  Build on same node
  Predefined Parameters TEST_UNIT=test4.rb
  Block until the triggered projects finish their builds ( Not selected this)
  </code></pre>
  
  <p>3) </p>
  
  <pre><code>   Created job "Child_test_job" as which was included in main_test_job like below
     Select Build step "Execute Shell" with below command
     script spec/$TEST_UNIT
  </code></pre>
  
  <p>When I start "Main_Test_job", it will automatically start 4 Child_Test_Jobs in same machine, which will reduce my total run time to 15 mins.</p>
  
  <ul>
  <li><p>But in this case "Main_test_job" has no way to monitor statuses of 4 
  child_test_jobs, It always succeeds immediately after starting 4<br>
  child jobs</p></li>
  <li><p>"Block until the triggered projects finish their builds" this option
  monitors child jobs but if we select this option for all child jobs,
  they are running sequentially instead of parallel.</p></li>
  </ul>
  
  <p>I can't use join plugin as I am not running different jobs instead triggering same job multiple times. </p>
  
  <p><strong>My Ideas:</strong></p>
  
  <ol>
  <li><p>have separate jobs for each test.rb and use join trigger to monitor
  statuses of all jobs</p></li>
  <li><p>have some shell script as the post-build task of "Main_Test_job"
      which will aggregate/monitor statuses/results of each jobs.</p></li>
  </ol>
  
  <p>I think this must be a common scenario in many organizations and there must be a easy way in Jenkins to achieve this.
  Please let me know your approaches/ideas. May be I am missing some thing here.</p>