问题描述
我正在使用Jenkins Pipeline插件执行iOS Checkout-Build-Test-Deploy管道.
I am using the Jenkins Pipeline plugin to execute an iOS Checkout-Build-Test-Deploy pipeline.
第一步涉及检查iDevice是否已实际连接(否则其余步骤将不执行).
One step involves checking whether an iDevice is actually connected (otherwise the rest of the steps will not be executed).
我想执行一个外壳命令idevice_id -l
(来自 libimobiledevice ),该命令将打印出所连接设备的设备ID,如果失败,则失败没有任何联系.
I want to execute a shell command idevice_id -l
(from libimobiledevice) which will print out the device ID of the connected device, or fail if nothing connected.
因此,我设想的步骤将是:
So the steps as I envision them, would be:
- 执行命令
sh "/usr/local/bin/idevice_id -l"
- 以某种方式解析输出 如果此命令不返回任何内容,则
- 失败.
- Execute command
sh "/usr/local/bin/idevice_id -l"
- parse the output somehow
- fail if this command does not return anything.
我已经阅读了大多数官方文档,但空白处.如何解析sh
步骤的输出?如果我以错误的方式处理此问题,欢迎提出任何其他建议.
I have read most of the official docs, but drew a blank. How do I parse the output of the sh
step?If I am approaching this in the wrong way, any other suggestions are welcome.
推荐答案
如此答案(版本)中所述2.4 of 管道:节点和流程 ,您可以使用:
As mentionned in this answer, as of version 2.4 of Pipeline: Nodes and Processes you can use:
def out = sh script: '/usr/local/bin/idevice_id -l', returnStdout: true
这篇关于Jenkins Pipeline插件:执行shell并解析输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!