[英]Get output of a python script into a variable in Jenkinsfile
I have a Python script which returns a string on stdout.我有一个 Python 脚本,它在标准输出上返回一个字符串。 The value rerturned by the python script can be collected in a bash script like below:
python 脚本返回的值可以在 bash 脚本中收集,如下所示:
#!/bin/bash
outputString=$(./my_python_script.py -some_parameter 2>&1)
echo "The output string is $outputString"
On a scripted pipeline with the Jenkinsfile
written in Groovy, I need to call my python script from the Jenkinsfile
and collect the output into a variable in the Jenkinsfile
.在使用
Jenkinsfile
编写的 Jenkinsfile 的脚本化管道上,我需要从 Jenkinsfile 调用我的Jenkinsfile
脚本并将Jenkinsfile
收集到 Jenkins 文件中的变量中。
Question:问题:
How do I do this provided that my Jenkinsfile run on a macOS node.如果我的 Jenkinsfile 在 macOS 节点上运行,我该怎么做。 Following is the way how I can at least get the output in a shell variable.
以下是我至少可以在 shell 变量中获得 output 的方法。
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
step parameters details: https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script sh
步骤参数详情: https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.