0

I am trying to run a python script in Jenkins. My Jenkins job is integrated with Jira & on build its gives JIRA_ISSUE_KEY. I want to save the value of JIRA_ISSUE_KEY in a variable.

import subprocess
e = 'echo "$JIRA_ISSUE_KEY"'
x = subprocess.call(e, shell=True)

Whenever I am doing print e it gives o/p as "echo "$JIRA_ISSUE_KEY"" & when I am doing print e its gives o/p as 0.

My overall output in Jenkins console is

JIRA comment is added
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/Jenkins Jira 
Integration Test
[Jenkins Jira Integration Test] $ python /tmp/jenkins2864498002834652992.py
MCO-15498
echo "$JIRA_ISSUE_KEY"
0
Finished: SUCCESS

I want to save the value MCO-15498 to some variable. How can I do that?

1 Answer 1

1

using bash script (or pipeline step sh), I would do:

JIRA_ISSUE_KEY=$(python my_python_script.py)
echo "$JIRA_ISSUE_KEY"

Your Answer

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

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