我有一个Python脚本,它在stdout上返回一个字符串。python脚本重新转换的值可以收集在如下bash脚本中:
#!/bin/bash
outputString=$(./my_python_script.py -some_parameter 2>&1)
echo "The output string is $outputString"
在使用Groovy编写的Jenkinsfile
的脚本化管道上,我需要从Jenkinsfile
调用python脚本,并将输出收集到Jenkinsfile
中的一个变量中。
问题:
如果我的Jenkinsfile在macOS节点上运行,我该如何做到这一点。以下是我如何至少在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'
}
}
def outputString = sh returnStdout:true, script:'./my_python_script.py -some_parameter 2>&1'
println "the output string is: ${outputString}"
sh
步骤参数详细信息:https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-外壳脚本