获取 python 脚本的输出到 Jenkinsfile 中的变量
Get output of a python script into a variable in Jenkinsfile
我有一个 Python 脚本,它 returns 标准输出上的一个字符串。 python 脚本返回的值可以收集在 bash 脚本中,如下所示:
#!/bin/bash
outputString=$(./my_python_script.py -some_parameter 2>&1)
echo "The output string is $outputString"
在 脚本管道 中 Jenkinsfile
写入 Groovy,我需要从 [=13] 调用我的 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-shell-script
我有一个 Python 脚本,它 returns 标准输出上的一个字符串。 python 脚本返回的值可以收集在 bash 脚本中,如下所示:
#!/bin/bash
outputString=$(./my_python_script.py -some_parameter 2>&1)
echo "The output string is $outputString"
在 脚本管道 中 Jenkinsfile
写入 Groovy,我需要从 [=13] 调用我的 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-shell-script