从 xcrun xctrace list devices 获取输出

get output from xcrun xctrace list devices

在詹金斯管道上,我执行:

def devicesText = sh(script: "xcrun xctrace list devices", returnStdout: true)
printf devicesText

它有奇怪的行为,因为它在控制台上打印输出但不将输出保存在变量中。控制台如下所示(id 已替换为 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX):

+ xcrun xctrace list devices
== Devices ==
SAM Team - Build Server 2018 (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)

== Simulators ==
Apple Watch Series 5 - 40mm (7.0) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
Apple Watch Series 5 - 44mm (7.0) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPad (7th generation) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPad Air (3rd generation) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPad Pro (11-inch) (2nd generation) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPad Pro (12.9-inch) (4th generation) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPad Pro (9.7-inch) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 11 (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 11 Pro (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 11 Pro Max (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 6s (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 8 (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone 8 Plus (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
iPhone SE (2nd generation) (13.5) (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
[Pipeline] echo

如您所见,回显是空的,因为它没有被复制到变量中。如何将输出保存在变量中?

(它曾经与已弃用的命令一起使用 instruments -s devices

我在使用 GitHub 操作的 xcodebuild 中遇到了类似的问题。我的解决方法是找到一个带有 xcrun xctrace list devices 的设备并直接在构建命令中使用它 ex: -destination "platform=$platform,name=iPhone 8".

我尝试使用匹配 iPhone* 的默认 regEx 和 grep 1 行,但它对我不起作用。

以某种方式 xcrun xctrace 将输出打印到 stderr

因此,为了让 stderr 登录 stdout,只需使用 2>&1.

将它们重定向到 stdout

-> xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{=;print}'