<p>The variable <code>GIT_AUTHOR</code> is only visible in the build step where it's defined. You can dump the parameters for the downstream job in a properties file:</p>

<pre>
cd $WORKSPACE/prancer/
GIT_AUTHOR=$(git show --format="%an" | head -1)

echo '-------------'
echo 'git_commit is '$GIT_COMMIT
echo 'git_branch is '$GIT_BRANCH
echo 'git_author is '$GIT_AUTHOR
echo '-------------'

cat > alex_test_pipeline.properties &lt&ltEOF
GIT_COMMIT = $GIT_COMMIT
GIT_BRANCH = $GIT_BRANCH
GIT_AUTHOR = $GIT_AUTHOR
EOF
</pre>

<p>In the <code>Trigger parameterized build...</code> step, replace the <code>Predefined parameters</code> with <code>Parameters from properties file</code> (or something like that - I don't remember the exact wording) and select the filename used above. You might also want to check <code>Build only if file exists</code>.</p>

CC BY-SA 4.0
2018-05-17T07:09:11.287Z
2018-05-17T07:09:11.287Z
simonz
<p>I have an upstream freestyle job and a downstream pipeline job. </p>

<p>The freestyle job is triggered via a Bitbucket hook to run whenever code is pushed to Bitbucket. </p>

<p>The freestyle job should capture the commit SHA and branch name and pass both to the pipeline job. It also generates a variable based on the branch author, that should also be passed. </p>

<p>In the freestyle job I do something like the following, which works and echos the expected parameters.</p>

<pre><code>cd $WORKSPACE/prancer/
GIT_AUTHOR=$(git show --format="%an" | head -1)

echo '-------------'
echo 'git_commit is '$GIT_COMMIT
echo 'git_branch is '$GIT_BRANCH
echo 'git_author is '$GIT_AUTHOR
echo '-------------'
</code></pre>

<p>I have the job configured to kick off the pipeline job like so;
<a href="https://i.sstatic.net/QdCGF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QdCGF.png" alt="freestyle job config"></a></p>

<p>Downstream, the pipeline job echos the <code>GIT_COMMIT</code> and <code>GIT_BRANCH</code> as expected. However, the <code>GIT_AUTHOR</code> just echos the variable name, not a value. </p>

<p>Somehow, the git commit and branch are being passed along, but the generated variable git_author isn't. I tried piping the author to a file, archiving it in the freestyle job and using the additional <code>Parameters from properties file</code> step, but that still isn't passing to the pipeline job. </p>

<p>I can confirm that</p>

<ol>
<li>GIT_AUTHOR has a value in the freestyle job</li>
<li>If I save GIT_AUTHOR to a properties file, I can view the file (with the author inside!) in the workspace of the freestyle job</li>
<li>The pipeline job isn't receiving the value, just the actual string <code>$GIT_AUTHOR</code>. If I check the parameters page for the triggered pipeline build commit and branch have values, author is the string <code>$GIT_AUTHOR</code>.</li>
</ol>

<p><strong>How do I use a generated variable's value from an upstream freestyle job when building a downstream pipeline job?</strong></p>

<jenkins><jenkins-pipeline>
Trigger downstream pipeline job via generated variable in upstream freestyle job
Alex
# Trigger downstream pipeline job via generated variable in upstream freestyle job

(Asked by: username_0 on 2018-05-01)

I have an upstream freestyle job and a downstream pipeline job. 
The freestyle job is triggered via a Bitbucket hook to run whenever code is pushed to Bitbucket. 
The freestyle job should capture the commit SHA and branch name and pass both to the pipeline job. It also generates a variable based on the branch author, that should also be passed. 
In the freestyle job I do something like the following, which works and echos the expected parameters.
cd $WORKSPACE/prancer/
GIT_AUTHOR=$(git show --format="%an" | head -1)

echo '-------------'
echo 'git_commit is '$GIT_COMMIT
echo 'git_branch is '$GIT_BRANCH
echo 'git_author is '$GIT_AUTHOR
echo '-------------'

I have the job configured to kick off the pipeline job like so;

Downstream, the pipeline job echos the GIT_COMMIT and GIT_BRANCH as expected. However, the GIT_AUTHOR just echos the variable name, not a value. 
Somehow, the git commit and branch are being passed along, but the generated variable git_author isn't. I tried piping the author to a file, archiving it in the freestyle job and using the additional Parameters from properties file step, but that still isn't passing to the pipeline job. 
I can confirm that

GIT_AUTHOR has a value in the freestyle job
If I save GIT_AUTHOR to a properties file, I can view the file (with the author inside!) in the workspace of the freestyle job
The pipeline job isn't receiving the value, just the actual string $GIT_AUTHOR. If I check the parameters page for the triggered pipeline build commit and branch have values, author is the string $GIT_AUTHOR.

How do I use a generated variable's value from an upstream freestyle job when building a downstream pipeline job?

**Tags:** jenkins, jenkins-pipeline


---

## 1 answers

### Answer by username_1 on 2018-05-17. Score: 2 | Accepted answer

The variable GIT_AUTHOR is only visible in the build step where it's defined. You can dump the parameters for the downstream job in a properties file:

cd $WORKSPACE/prancer/
GIT_AUTHOR=$(git show --format="%an" | head -1)

echo '-------------'
echo 'git_commit is '$GIT_COMMIT
echo 'git_branch is '$GIT_BRANCH
echo 'git_author is '$GIT_AUTHOR
echo '-------------'

cat > alex_test_pipeline.properties <

In the Trigger parameterized build... step, replace the Predefined parameters with Parameters from properties file (or something like that - I don't remember the exact wording) and select the filename used above. You might also want to check Build only if file exists.


---

