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

macOS自托管Azure Pipeline Agent运行iOS归档失败问题

针对M1 Mac Azure自托管Agent launchd模式归档失败的解决方案

环境变量差异修复

launchd服务的运行环境和终端交互模式存在明显差异,xcodebuild可能无法正确定位工具链或访问资源:

  • 找到Agent生成的launchd配置文件(路径:~/Library/LaunchAgents/vsts.agent.<你的账户名>.<你的Agent名>.plist)
  • 添加环境变量配置到plist中:
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Xcode.app/Contents/Developer/usr/bin</string>
      <key>HOME</key>
      <string>/Users/<你的用户名></string>
      <key>DEVELOPER_DIR</key>
      <string>/Applications/Xcode.app/Contents/Developer</string>
    </dict>
    
  • 重启Agent服务:./svc.sh stop && ./svc.sh start

代码签名权限配置

launchd运行时可能没有钥匙串的访问权限,导致签名验证失败:

  1. 打开钥匙串访问,找到你的代码签名证书,右键显示简介,在信任标签下将「使用此证书时」设为「始终信任」
  2. 在流水线的前置步骤中添加钥匙串解锁命令:
    security unlock-keychain -p <你的钥匙串密码> /Users/<你的用户名>/Library/Keychains/login.keychain-db
    
    注意:避免明文密码,可通过Azure Pipelines的变量存储密码

解决DerivedData循环冲突问题

你遇到的“成功一次失败一次”的现象,基本是DerivedData目录的缓存锁定或冲突导致:

  • 修改xcodebuild命令,指定专属的DerivedData目录:
    xcodebuild -workspace ~/repos/<project>/<project>.xcworkspace -scheme <app-name> -allowProvisioningUpdates clean archive -archivePath build/<app-name> -destination generic/platform=iOS -derivedDataPath ~/repos/<project>.deriveddata
    
  • 在归档步骤前强制清理旧缓存:
    rm -rf ~/repos/<project>.deriveddata
    rm -rf ~/repos/<project>/build
    

排查ValidateEmbeddedBinary详细错误

如果以上方法无效,需要获取完整的构建日志定位问题:

  • 在xcodebuild命令中添加-verbose参数,输出详细日志:
    xcodebuild -verbose -workspace ~/repos/<project>/<project>.xcworkspace -scheme <app-name> -allowProvisioningUpdates clean archive -archivePath build/<app-name> -destination generic/platform=iOS
    
  • 查看日志中ValidateEmbeddedBinary步骤的具体报错,通常会提示签名不匹配、Provisioning Profile无效或二进制权限异常

确认launchd运行用户

确保Agent服务以普通用户身份运行,而非root:

  • 检查plist文件中的UserName字段,确认是你的用户名
  • 若之前以root安装,先卸载服务:./svc.sh uninstall,再用普通用户重新安装启动:./svc.sh install && ./svc.sh start

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 11:55:36