[英]Return a list of values from Python Script to Jenkins Pipeline
I have a jenkins pipeline which contains the following 3 stages(just description): 我有一个詹金斯管道,其中包含以下3个阶段(仅作说明):
Stage 1: Calling a python script, that should return a list of version numbers for which a new release should be built 第1阶段:调用python脚本,该脚本应返回应为其构建新发行版的版本号列表
Stage 2: Call Jenkins-Jobs that do the built for every version number of Stage 1 in parallel. 阶段2:呼叫Jenkins-Jobs,它们并行地为阶段1的每个版本号进行构建。
Stage 3: After all built jobs have finished do other stuff with the built releases. 阶段3:在完成所有已构建的作业之后,对已构建的发行版执行其他操作。
The issue I got is, I don't know how to process the output of the python script. 我遇到的问题是,我不知道如何处理python脚本的输出。 How can I use a list, that is returned from a python function for the following Stages? 在接下来的阶段中,如何使用从python函数返回的列表?
I call the python script via a bat
command. 我通过bat
命令调用python脚本。 I saw, there is the possibility to redirect the output of a batch command via returnStdout
flag, but this only passes the output of the python script. 我看到,可以通过returnStdout
标志重定向批处理命令的输出,但这仅传递python脚本的输出。
One possiblity I can think of is to store the list in a json file in the workspace and then read it back in with readJson
in the pipeline. 我可以想到的一种可能是将列表存储在工作区中的json文件中,然后在管道中使用readJson
读回该列表。 But maybe there is a more elegant solution to this. 但是也许对此有一个更优雅的解决方案。
Since you're using the Pipeline DSL, you can use Groovy to process the result of the call to bat
由于您正在使用管道DSL,因此可以使用Groovy处理对bat
的调用结果
pipeline {
agent any
steps {
step('Get Build Numbers') {
script {
def version_numbers = bat(script: 'python get_version_numbers.py', returnStdout: true)
def versions_as_array = version_numbers.split('\n')
}
}
}
}
From there, it's a matter of generating the build steps and wrapping them in a parallel block. 从那里开始,就需要生成构建步骤并将其包装在并行块中。 For that, take a look at this answer: Ideas to implement dynamic parallel build using jenkins pipeline plugin 为此,请看一下以下答案: 使用jenkins管道插件实现动态并行构建的想法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.