<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>

CC BY-SA 4.0
2019-11-23T10:39:45.640Z
I clarified the question. Can  you have a look?
arielma
CC BY-SA 4.0
2019-11-22T21:07:26.973Z
2019-11-22T21:07:26.973Z
Argyle
<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>

<jenkins-pipeline><python><groovy>
How to save groovy output to pipeline variable
arielma
# 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?
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?  

---

