2

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; freestyle job config

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

  1. GIT_AUTHOR has a value in the freestyle job
  2. 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
  3. 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?

1 Answer 1

2

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 <<EOF
GIT_COMMIT = $GIT_COMMIT
GIT_BRANCH = $GIT_BRANCH
GIT_AUTHOR = $GIT_AUTHOR
EOF

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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