7

I need to trigger a Jenkins job from another job and pass various values to it for later conditional logic. It seems the Parameterized Trigger Plugin will do exactly what I need. (https://plugins.jenkins.io/parameterized-trigger)

However this plugin I'm not seeing anything regarding pipeline syntax both on the doc as well as in the syntax builder.

Most all plugins I've used allow use within pipeline scripts. (Jenkinsfiles). They rarely have documentation for syntax but I can typically just use the Syntax builder inside Jenkins to get the right pipeline syntax to use the plugin.

Is it possible to use this plugin within a pipeline (multi-branch pipeline to be specific)?

If not, then is there any alternative ways to do what I need to do from a Jenkins pipeline? (Trigger another job while passing some value/parameter to it).

emmdee
  • 1,935
  • 9
  • 35
  • 56

1 Answers1

6

You don't need a plugin at all to do this. The built-in Pipeline build step supports parameters. E.g.:

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

You should also be able to use the syntax generator with the default build step to help generate this code.

jayhendren
  • 917
  • 4
  • 11
  • 1
    Thank you, I'll give this a shot and mark your answer as accepted in a bit. Side question: can you think of why the parameterized plugin mentioned exists at all? – emmdee Jun 08 '18 at 21:57
  • 2
    In Jenkins, everything is implemented as a plugin - even the Pipeline build step I mentioned in my answer is technically a plugin (it gets installed as a dependency of the core Pipeline plugins, so it's treated more like a built-in feature). The Parameterized Build Trigger plugin is an official plugin developed by the Jenkins developers and it dates back to the pre-Pipeline era of Jenkins, when it was one of the easiest ways to trigger a parameterized build from another build. – jayhendren Jun 09 '18 at 01:45
  • @jayhendren Unfortunately, the build step doesn't seem to offer the same capabilities as the Parameterized Trigger plugin. For example, if one had a job configured to trigger from the GHPRB plugin, then wanted to pass all the parameters of this trigger job to the downstream job, then we wouldn't want to have to define all the various GHPRB build parameters in the downstream job and just pass through all. With the Parameterized Trigger plugin this was possible by selecting "Current build parameters" when adding parameters. The Jenkins pipeline build step does not seem to support this. – Hazok May 18 '20 at 20:28