Jenkins Pipeline Plugin:执行shell并解析输出 [英] Jenkins Pipeline Plugin: execute shell and parse output

查看:21
本文介绍了Jenkins Pipeline Plugin:执行shell并解析输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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).

我想执行一个shell命令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.

所以我设想的步骤是:

  • 执行命令sh "/usr/local/bin/idevice_id -l"
  • 以某种方式解析输出
  • 如果此命令不返回任何内容,则失败.

我已经阅读了大部分官方文档,但还是一片空白.如何解析 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.

推荐答案

this answer 中所述,截至版本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 Plugin:执行shell并解析输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆