Answers: <p>using bash script (or pipeline step <code>sh</code>), I would do:</p>
  
  <pre><code>JIRA_ISSUE_KEY=$(python my_python_script.py)
  echo "$JIRA_ISSUE_KEY"
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-23T21:27:02.973Z
Answers: 2019-04-23T21:27:02.973Z
Answers: fredericrous
Body: <p>I am trying to run a python script in Jenkins. My Jenkins job is integrated with Jira &amp; on build its gives JIRA_ISSUE_KEY. I want to save the value of JIRA_ISSUE_KEY in a variable.</p>
  
  <pre><code>import subprocess
  e = 'echo "$JIRA_ISSUE_KEY"'
  x = subprocess.call(e, shell=True)
  </code></pre>
  
  <p>Whenever I am doing print e it gives o/p as "echo "$JIRA_ISSUE_KEY"" &amp; when I am doing print e its gives o/p as 0.</p>
  
  <p>My overall output in Jenkins console is </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I want to save the value MCO-15498 to some variable. How can I do that?</p>
  
Tags: <jenkins><python>
Title: Python Script in Jenkins
UserDisplayName: Prashast
ThreadText: # Python Script in Jenkins
  
  (Asked by: username_0 on 2019-04-08)
  
  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?
  
  **Tags:** jenkins, python
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-23. Score: 1 | Accepted answer
  
  using bash script (or pipeline step `sh`), I would do:
  
  ```
  JIRA_ISSUE_KEY=$(python my_python_script.py)
  echo "$JIRA_ISSUE_KEY"
  
  ```
  
  
  ---
  
  