You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure DevOps流水线中查看Xcode构建阶段脚本日志?

关于Azure DevOps Xcode任务与React Native构建阶段日志的疑问

问题背景

我有一个位于nx monorepo中的React Native应用,本地可正常运行、归档和构建。但通过Azure DevOps流水线的Xcode构建任务执行时,遇到了日志不显示的问题。流水线YAML配置如下:

#Your build pipeline references an undefined variable named ‘Parameters.scheme’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.xcodeVersion’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘APPLE_CERTIFICATE_SIGNING_IDENTITY’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘APPLE_PROV_PROFILE_UUID’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972

steps:
- task: Xcode@5
  displayName: 'Xcode Build to Generate the signed IPA'
  inputs:
    actions: 'clean build -verbose'
    xcWorkspacePath: 'apps/my-app/ios/MyApp.xcworkspace'
    scheme: '$(Parameters.scheme)'
    xcodeVersion: '$(Parameters.xcodeVersion)'
    packageApp: true
    exportOptions: specify
    exportMethod: 'ad-hoc'
    signingOption: manual
    signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
    provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'

流水线执行的命令为:

xcodebuild -sdk iphoneos -configuration Release -workspace ios/MyApp.xcworkspace -scheme MyApp clean build -verbose

本地执行该命令时,能正常打印出我在Xcode>Target(MyApp)>BuildPhases>Bundle React Native code and images中添加的调试日志:

echo "\n 0. ⚛️🍀 DEBUG PIPELINE: Bundle React Native code and images \n"
echo "\n 1. ⚛️🍀 cd \$PROJECT_DIR/.."
pwd
ls

cd $PROJECT_DIR/..
export NODE_BINARY=node
./node_modules/react-native/scripts/react-native-xcode.sh

echo "\n 0. 🩸 DEBUG PIPELINE: Bundle React Native code and images::SCRIPT COMPLETED \n"

但这些日志在Azure DevOps流水线中完全不显示,即使启用「Enable system diagnostics」也无效。现需确认以下问题:

  1. 上述Azure DevOps Xcode构建任务是否使用相同的阶段脚本?
  2. 是否会移除日志?
  3. 是否使用了其他构建阶段脚本?
  4. 如何在Azure DevOps流水线日志中查看构建阶段脚本的日志?

解答

1. 是否使用相同的阶段脚本?

是的,Azure DevOps的Xcode@5任务本质是调用xcodebuild命令执行构建,和本地执行的命令逻辑一致,会触发Xcode项目中配置的所有Build Phases脚本,包括你自定义的Bundle React Native code and images阶段脚本。

2. 是否会移除日志?

Xcode@5任务默认不会主动移除Build Phases的日志,但存在两种常见情况导致日志不显示:

  • 日志级别过滤:流水线默认可能过滤部分标准输出(stdout),只显示错误输出(stderr)。你的echo语句输出到stdout,可能被默认日志级别屏蔽。
  • 工作目录差异:nx monorepo的路径结构可能导致流水线中$PROJECT_DIR指向和本地不一致,脚本执行失败但未触发错误日志,或者echo输出被吞掉。

3. 是否使用了其他构建阶段脚本?

不会,Xcode任务严格按照Xcode项目中配置的Build Phases执行,不会替换或添加额外的构建阶段脚本。如果流水线构建行为和本地有差异,大概率是环境变量、路径或权限问题,而非脚本被替换。

4. 如何在流水线中查看构建阶段脚本的日志?

可以通过以下几种方式强制输出日志:

  • 修改echo输出到stderr:把echo命令改为echo "xxx" >&2,将输出重定向到标准错误流,流水线会默认捕获并显示这部分内容。
  • 调整Xcode任务的日志参数:在actions中添加-quiet NO,或者直接在xcodebuild命令后追加OTHER_CFLAGS="-v",强制Xcode输出更详细的构建日志。
  • 单独执行脚本并捕获日志:在Xcode任务之前,添加一个Bash任务,手动执行Bundle React Native code and images中的脚本内容,直接在流水线中输出日志,方便排查路径或环境问题:
    cd apps/my-app/ios
    echo "\n 0. ⚛️🍀 DEBUG PIPELINE: Bundle React Native code and images \n" >&2
    cd ..
    export NODE_BINARY=node
    ./node_modules/react-native/scripts/react-native-xcode.sh
    echo "\n 0. 🩸 DEBUG PIPELINE: Bundle React Native code and images::SCRIPT COMPLETED \n" >&2
    
  • 启用完整日志模式:除了「Enable system diagnostics」,还可以在流水线的变量中添加system.debug=true,强制输出所有日志内容,包括stdout的输出。

内容的提问来源于stack exchange,提问作者iamcastelli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:45:35