0

I'm trying to apply the guidance I recently read at how to trigger parameterized builds from a different build in Jenkins and https://plugins.jenkins.io/parameterized-trigger/ - but this doesn't seem to work, and I'd like to ask the community for help understanding what I'm doing wrong.

My jobs are set up thus:

  • foo2 is a non-parameterized build
    • foo2's Build is Execute shell with commands:
    string1="123abc"
    export string2="456def"
    
    • foo2's Post-build Action is Trigger parameterized build on other projects
      • It triggers foo3
      • It attempts to pass parameters to foo3 with Predefined parameters:
      a_string=${string1}
      b_string=${string2}
      
  • foo3 is a parameterized build with two string paramters: a_string and b_string.
    • foo3's Build step is Execute shell with commands:
    echo ${a_string}
    echo ${b_string}
    

Question/Problem: when foo3 is triggered, its console output are the string literals ${string1} and ${string2}, instead of the desired 123abc and 456def -- what am I doing wrong? How can I pass variables set during foo2's Build stage to foo3?

Output of foo3 build:

Started by upstream project "foo2" build number 4
originally caused by:
 Started by user unknown or anonymous
Running as SYSTEM
Building remotely on builder-231 (docker-cleanup) in workspace /home/user/workspace/foo3
[foo3] $ /bin/sh -xe /tmp/jenkins2920927890739081404.sh
+ echo ${string1}
${string1}
+ echo ${string2}
${string2}
Finished: SUCCESS

Screenshots:

foo2's Build and Post-build action to trigger foo3: foo2's Build and Post-build action to trigger foo3


foo3's parameters: foo3's parameters


foo3's Build enter image description here

1
  • IIRC string1 and string2 will not available outside Execute shell step so the values of a_string and b_string will be empty for foo3 build.
    – Oli
    May 15 at 10:24
0

Use a Pipeline.

pipeline {
  agent any

  stages {

    stage('run job foo3') { 
      steps {
        script {
          
          string1 = "123abc"
          string2 = "456def"
          
          build job: 'foo3', 
            parameters: [
              // both is possible
              string(name: 'a_string', value: "${string1}"),
              string(name: 'b_string', value: string2)
            ]
            wait: true

         }
       }
     }
   }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.