Answers: <p>You can send the output of your python script to <code>stdout</code> and capture it in a environment variable and that variable can be passed to other stages in the pipeline. Also, the environment variables can be used inside the scripts.</p>
  
  <p>You can do something like this:</p>
  
  <pre><code>def call(Map parameters)
  {
      def CREDENITAL_ID = parameters.secret
      def DOMAIN_DESCRIPTOR_URL = parameters.url
      env.artifacts = sh(script: "python amd_distribution_input_transformation.py", returnStdout: true )
  
      }             
  }
  </code></pre>
  
  <p>Here, the output of the script <code>amd_distribution_input_transformation.py</code> will be stored in the variable <code>artifacts</code> and will be available further.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-18T20:51:27.270Z
Answers: how can I use/access env.artifacts in the pipeline?
Answers: arielma
Answers: CC BY-SA 4.0
Answers: 2019-11-18T21:44:53.087Z
Answers: `artifacts` is just a variable. Say the python script has returned you a string separated with commas, you can put it in pipeline stage as `amd_distribution_create_bundle credential_id: artifacts.split()` to pass a list to your script.
Answers: Samit
Answers: CC BY-SA 4.0
Answers: 2019-11-19T22:35:41.243Z
Answers: Tnx, I will try and update. BTW, is there a second option, to save the python output to Linux file and then define pipeline variable which gets its value?
Answers: arielma
Answers: CC BY-SA 4.0
Answers: 2019-11-18T20:45:05.053Z
Answers: 2019-11-18T20:45:05.053Z
Answers: Samit
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>groovy code:</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 JSON object named 'artifacts_list'</p>
  
  <p>my question is, how can I access this object in my next stage in the pipeline:</p>
  
  <pre><code>stage ("create bundle"){
              steps{
                  script{
                      amd_distribution_create_bundle credential_id: artifacts_list
                      }
                  }
              }
  </code></pre>
  
Tags: <jenkins-pipeline><groovy>
Title: How to pass groovy output to pipeline variable
UserDisplayName: arielma
ThreadText: # How to pass groovy output to pipeline variable
  
  (Asked by: username_0 on 2019-11-18)
  
  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
                  }
              }
          }
  
  ```
  
  groovy code:
  
  ```
  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 JSON object named 'artifacts\_list'
  
  my question is, how can I access this object in my next stage in the pipeline:
  
  ```
  stage ("create bundle"){
              steps{
                  script{
                      amd_distribution_create_bundle credential_id: artifacts_list
                      }
                  }
              }
  
  ```
  
  **Tags:** jenkins-pipeline, groovy
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-18. Score: 1 | Accepted answer
  
  You can send the output of your python script to `stdout` and capture it in a environment variable and that variable can be passed to other stages in the pipeline. Also, the environment variables can be used inside the scripts.
  
  You can do something like this:
  
  ```
  def call(Map parameters)
  {
      def CREDENITAL_ID = parameters.secret
      def DOMAIN_DESCRIPTOR_URL = parameters.url
      env.artifacts = sh(script: "python amd_distribution_input_transformation.py", returnStdout: true )
  
      }             
  }
  
  ```
  
  Here, the output of the script `amd_distribution_input_transformation.py` will be stored in the variable `artifacts` and will be available further.
  
  > **Comments:**
  > **username_0**: how can I use/access env.artifacts in the pipeline?  
  > **username_1**: `artifacts` is just a variable. Say the python script has returned you a string separated with commas, you can put it in pipeline stage as `amd_distribution_create_bundle credential_id: artifacts.split()` to pass a list to your script.  
  > **username_0**: Tnx, I will try and update. BTW, is there a second option, to save the python output to Linux file and then define pipeline variable which gets its value?  
  
  ---
  
  