将Python脚本的输出结果存入Jenkinsfile变量

3

我有一个Python脚本,它在标准输出上返回一个字符串。可以通过以下方式在Bash脚本中收集Python脚本返回的值:

#!/bin/bash

outputString=$(./my_python_script.py -some_parameter 2>&1)
echo "The output string is $outputString"

在使用Groovy编写的脚本管道中,我需要从Jenkinsfile调用我的Python脚本,并将输出收集到Jenkinsfile中的变量中。问题是:如何在macOS节点上运行Jenkinsfile并将输出保存在shell变量中?
stage('My build') {
    node('my_build_node') {
        sh 'output_string=$(./my_python_script.py -some_parameter 2>&1) && sh 'echo The output_string is $output_string'
    }
}
1个回答

5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接