Answers: <p>Have you tried setting <code>returnStdout</code> to true in the <code>sh()</code> command per the <a href="https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script" rel="nofollow noreferrer">Jenkins documentation</a>?</p>
  
  <p>You can then assign that output to a variable within your pipeline:</p>
  
  <pre><code>def artifactsList = sh(label: 'Running amd_distribution_input transformation', returnStdout: true, script: 'python amd_distribution_input_transformation.py')
  </code></pre>
  
  <p>and check what kind of object that variable is, and act on it accordinly</p>
  
  <pre><code>echo(artifactsList.getClass())
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-23T10:39:45.640Z
Answers: I clarified the question. Can  you have a look?
Answers: arielma
Answers: CC BY-SA 4.0
Answers: 2019-11-22T21:07:26.973Z
Answers: 2019-11-22T21:07:26.973Z
Answers: Argyle
Body: <p>I have the below code in the jenkisn pipeline:</p>
  
  <pre><code>   stage ("amd_distribution_input_transformation"){
          steps{
              script{
                      amd_distribution_input_transformation url: params.DOMAIN_DESCRIPTOR_URL, secret: params.CERDENITAL_ID
                  }
              }
          }
  </code></pre>
  
  <p>amd_distribution_input_transformation.groovy content:</p>
  
  <pre><code>def call(Map parameters)
  {
      def CREDENITAL_ID = parameters.secret
      def DOMAIN_DESCRIPTOR_URL = parameters.url
      sh '''
          python amd_distribution_input_transformation.py
        '''
      }             
  }
  </code></pre>
  
  <p>in the amd_distribution_input_transformation.py some code is running, and at the end, it returns object named 'artifacts_list'</p>
  
  <p>my question is, how can I assign the return obect from groovy file to pipeline variable.
  BTW, if it helps, I can write the output to json file from the python code (and here I'm stuck on how eventually assign that file to the pipeline variable)</p>
  
Tags: <jenkins-pipeline><python><groovy>
Title: How to save groovy output to pipeline variable
UserDisplayName: arielma
ThreadText: # How to save groovy output to pipeline variable
  
  (Asked by: username_0 on 2019-11-22)
  
  I have the below code in the jenkisn pipeline:
  
  ```
     stage ("amd_distribution_input_transformation"){
          steps{
              script{
                      amd_distribution_input_transformation url: params.DOMAIN_DESCRIPTOR_URL, secret: params.CERDENITAL_ID
                  }
              }
          }
  
  ```
  
  amd\_distribution\_input\_transformation.groovy content:
  
  ```
  def call(Map parameters)
  {
      def CREDENITAL_ID = parameters.secret
      def DOMAIN_DESCRIPTOR_URL = parameters.url
      sh '''
          python amd_distribution_input_transformation.py
        '''
      }             
  }
  
  ```
  
  in the amd\_distribution\_input\_transformation.py some code is running, and at the end, it returns object named 'artifacts\_list'
  
  my question is, how can I assign the return obect from groovy file to pipeline variable.
  BTW, if it helps, I can write the output to json file from the python code (and here I'm stuck on how eventually assign that file to the pipeline variable)
  
  **Tags:** jenkins-pipeline, python, groovy
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-22. Score: 1 | Accepted answer
  
  Have you tried setting `returnStdout` to true in the `sh()` command per the [Jenkins documentation](https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script)?
  
  You can then assign that output to a variable within your pipeline:
  
  ```
  def artifactsList = sh(label: 'Running amd_distribution_input transformation', returnStdout: true, script: 'python amd_distribution_input_transformation.py')
  
  ```
  
  and check what kind of object that variable is, and act on it accordinly
  
  ```
  echo(artifactsList.getClass())
  
  ```
  
  > **Comments:**
  > **username_0**: I clarified the question. Can  you have a look?  
  
  ---
  
  