<p>Use a Pipeline.</p>
<pre><code>pipeline {
  agent any

  stages {

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

         }
       }
     }
   }
 }
</code></pre>

CC BY-SA 4.0
2021-06-30T11:49:40.577Z
2021-06-30T11:49:40.577Z
David
<p>I'm trying to apply the guidance I recently read at <a href="https://stackoverflow.com/questions/28079228/passing-build-parameters-from-one-jenkins-project-to-another-jenkins-project">how to trigger parameterized builds from a different build in Jenkins</a> and <a href="https://plugins.jenkins.io/parameterized-trigger/" rel="nofollow noreferrer">https://plugins.jenkins.io/parameterized-trigger/</a> - <strong>but this doesn't seem to work, and I'd like to ask the community for help understanding what I'm doing wrong</strong>.</p>
<p>My jobs are set up thus:</p>
<ul>
<li><code>foo2</code> is a non-parameterized build
<ul>
<li><code>foo2</code>'s Build is <code>Execute shell</code> with commands:</li>
</ul>
<pre><code>string1=&quot;123abc&quot;
export string2=&quot;456def&quot;
</code></pre>
<ul>
<li><code>foo2</code>'s Post-build Action is <code>Trigger parameterized build on other projects</code>
<ul>
<li>It triggers <code>foo3</code></li>
<li>It <em>attempts</em> to pass parameters to <code>foo3</code> with <code>Predefined parameters</code>:</li>
</ul>
<pre><code>a_string=${string1}
b_string=${string2}
</code></pre>
</li>
</ul>
</li>
<li><code>foo3</code> is a parameterized build with two string paramters: <code>a_string</code> and <code>b_string</code>.
<ul>
<li><code>foo3</code>'s Build step is <code>Execute shell</code> with commands:</li>
</ul>
<pre><code>echo ${a_string}
echo ${b_string}
</code></pre>
</li>
</ul>
<p><strong>Question/Problem: when <code>foo3</code> is triggered, its console output are the string literals <code>${string1}</code> and <code>${string2}</code>, instead of the desired <code>123abc</code> and <code>456def</code> -- what am I doing wrong? How can I pass variables set during <code>foo2</code>'s Build stage to <code>foo3</code>?</strong></p>
<p>Output of <code>foo3</code> build:</p>
<pre><code>Started by upstream project &quot;foo2&quot; 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
</code></pre>
<hr />
<p>Screenshots:</p>
<p><code>foo2</code>'s Build and Post-build action to trigger <code>foo3</code>:
<a href="https://i.sstatic.net/VFUso.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VFUso.png" alt="foo2's Build and Post-build action to trigger foo3" /></a></p>
<hr />
<p><code>foo3</code>'s parameters:
<a href="https://i.sstatic.net/h6ijB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/h6ijB.png" alt="foo3's parameters" /></a></p>
<hr />
<p><code>foo3</code>'s Build
<a href="https://i.sstatic.net/4hkNx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4hkNx.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-05-15T10:24:54.423Z
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
<jenkins><variables>
Why is parameter not propagated to post-build parameterized build?
StoneThrow
# Why is parameter not propagated to post-build parameterized build?

(Asked by: username_0 on 2021-05-14)

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:


foo3's parameters:


foo3's Build

**Tags:** jenkins, variables

> **Comments:**
> **username_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.  

---

## 1 answers

### Answer by username_2 on 2021-06-30. Score: 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

         }
       }
     }
   }
 }


---

