¯\_(ツ)_/¯

thunder@home:~$

This is my home blog, mostly to share some useful info or code snippets
< 1 min

Heya,

Just a small groovy code snippet to trigger another job with parameters via Jenkins Scripted Pipeline:

build(
  job: 'my-job-name',
  parameters: [
    [
      $class: 'StringParameterValue',
      name: 'myStringParameter',
      value: "my value",
    ],
    [
      $class: 'BooleanParameterValue',
      name: 'myBooleanParameter',
      value: true,
    ],
    // etc.
  ],
)

And if we might want to run several jobs in parallel then we do following:

node("master") {
  List<String> jobNames = [
    "test-folder/test-job-1",
    "test-folder/test-job-2",
    "test-folder/test-job-3",
  ]
  Map jobs = [:]
  jobNames.each {
    jobName -> jobs["job-${jobName}"] = {
      stage("Trigger ${jobName}") {
        build(
          job: "${jobName}",
          wait: true,
          propagate: true,
          parameters: [
            [
              $class: 'StringParameterValue',
              name: 'SOME_PARAMETER',
              value: "SOME_VALUE",
            ],
          ],
        )
      }
    }
  }
  parallel jobs
}

That’s it

Happy pipelining!

Thank You For Reading