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

To use PARALLEL in Job DSL Plugin

XMLWordPrintable

      I am able to run this in the "Pipeline" project type.

      import groovy.json.JsonSlurperClassic

      def TARGET_IP = "104.239.251.41"
      def test_dir = "/home/ubuntu/workspace/Athena/modules/delorean/test-api"
      def testJobs = [:]

      @NonCPS
      def slurpJSON(text) {
      final slurper = new JsonSlurperClassic()
      return slurper.parseText(text)
      //return new HashMap<>(slurper.parseText(inputFile)) => not serializable
      }

      @NonCPS
      buildCommand(domain, TARGET_IP, test_dir) {
      def sb = new StringBuffer()
      return sb.plus('ATHENA_ENV_TARGET_IP=' + TARGET_IP)
      .plus(' ATHENA_ENV_TARGET_DOMAIN=' + domain)
      .plus(' ATHENA_ENV_TARGET_PROXY=http://athena-plugin-proxy-' + domain)
      .plus(' ATHENA_ENV_TARGET_REPORT=report_' + domain)
      .plus(' ATHENA_INSTANCE=' + domain)
      .plus(' /home/ubuntu/athena/athena php api ' + test_dir)
      .plus(' ' + test_dir +'/athena.json')
      .plus(' || ( sudo mv ' + test_dir + '/report_' + domain)
      .plus('/report.html ' + test_dir + '/report_' + domain + '.html && exit 1)')

      }

      node('athena'){
      def aw = Jenkins.instance.getJob('Athena').lastBuild.workspace;
      //def athenaSufix = "/modules/delorean/test-api/athena.json"
      //def athenaJson = aw + athenaSufix

      echo '\tWorking with domains under =>' + aw
      def inputJSON = slurpJSON(readFile('/home/ubuntu/workspace/Athena/modules/delorean/test-api/athena.json'))

      //echo '\tList size = ' + inputJSON["proxy"]["remapHosts"].size()

      def domains = []
      for (param in inputJSON.proxy.remapHosts)

      { domains.add(param.getKey()) //println "\t\tParam domains = " + param.getKey() }

      inputJSON = null
      echo '\tFinished loading domains'
      i = 0
      for (domain in domains) {
      //println "\t\tDomain = " + domain
      def command = buildCommand(domain, TARGET_IP, test_dir)

      testJobs["split${i}"] = {
      node('athena')

      { //echo '\t\tCommand = ' + command sh command }

      }
      i++
      }

      parallel testJobs

      }

      The Job DSL Plugin allow me to run all BUT the PARALLEL.

            daspilker Daniel Spilker
            yael_lorenzo Yael Lorenzo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: