Microsoft App Center 构建失败:多个命令生成 'appcenter-pre-build.sh'

Microsoft App Center build failed: Multiple commands produce 'appcenter-pre-build.sh'

序曲

我正在为我的应用程序的 CI 使用默认 "Push hook" 的 App Center,每次我推送到分支时都会重建。我的任务是将 API 端点作为 App Center 变量传递,该变量是在构建配置中配置的。

此外,我还有我的 appcenter-pre-build.sh 脚本,它与 .xcworkspace 文件放在同一目录中(如 official documentation 中所述)。脚本本身如下所示:

#!/usr/bin/env bash

echo "EXECUTING APPCENTER_PRE_BUILD SCRIPT"

if [ -z "$VERSION_CODE_SHIFT" ]
then
    echo "You need define the VERSION_CODE_SHIFT variable in App Center"
    exit
fi

if [ -z "$ENDPOINT" ]
then
    echo "You need define the ENDPOINT variable in App Center"
    exit
fi

PLIST_PATH="VideoApp/VideoApp/Info.plist"

VERSION_CODE=$((VERSION_CODE_SHIFT + APPCENTER_BUILD_ID))

APP_CENTER_CURRENT_PLATFORM="ios"

if [ "$APP_CENTER_CURRENT_PLATFORM" == "ios" ]
then
    plutil -replace CFBundleVersion -string "$VERSION_CODE" $PLIST_PATH
    echo "Updated version code in $PLIST_PATH to new value: $VERSION_CODE"
    plutil -replace CFBundleShortVersionString -string "${MARKETING_VERSION}.$VERSION_CODE" $PLIST_PATH
    echo "Updated marketing version in $PLIST_PATH to new value: ${MARKETING_VERSION}.$VERSION_CODE"
    plutil -replace HubEndpoint -string "$ENDPOINT" $PLIST_PATH
    echo "Updated HubEndpoint in $PLIST_PATH to new value: $ENDPOINT"
fi

所以,基本上,我从 App Center 提取环境变量并修改我的 Info.plist,然后在代码中使用它的属性来设置 API 端点。另外,如您所见,应用程序的版本正在以类似的方式进行修改。

问题

App Center 构建最终失败并出现以下错误:

error: Multiple commands produce '/Users/runner/Library/Developer/Xcode/DerivedData/VideoApp-gpxrsqjtrulyrqamenreayeeatqj/Build/Intermediates.noindex/ArchiveIntermediates/Video-Community/InstallationBuildProductsLocation/Applications/PC365.app/appcenter-pre-build.sh':

1) Target 'Video-Community' (project 'VideoApp') has copy command from '/Users/runner/runners/2.168.2/work/1/s/VideoApp/VideoApp/appcenter-pre-build.sh' to '/Users/runner/Library/Developer/Xcode/DerivedData/VideoApp-gpxrsqjtrulyrqamenreayeeatqj/Build/Intermediates.noindex/ArchiveIntermediates/Video-Community/InstallationBuildProductsLocation/Applications/PC365.app
/appcenter-pre-build.sh'
2) Target 'Video-Community' (project 'VideoApp') has copy command from '/Users/runner/runners/2.168.2/work/1/s/VideoApp/appcenter-pre-build.sh' to '/Users/runner/Library/Developer/Xcode/DerivedData/VideoApp-gpxrsqjtrulyrqamenreayeeatqj/Build/Intermediates.noindex/ArchiveIntermediates/Video-Community/InstallationBuildProductsLocation/Applications/PC365.app
/appcenter-pre-build.sh'


warning: duplicate output file '/Users/runner/Library/Developer/Xcode/DerivedData/VideoApp-gpxrsqjtrulyrqamenreayeeatqj/Build/Intermediates.noindex/ArchiveIntermediates/Video-Community/InstallationBuildProductsLocation/Applications/PC365.app/appcenter-pre-build.sh' on task: CpResource /Users/runner/runners/2.168.2/work/1/s/VideoApp/appcenter-pre-build.sh /Users/runner/Library/Developer/Xcode/DerivedData/VideoApp-gpxrsqjtrulyrqamenreayeeatqj/Build/Intermediates.noindex/ArchiveIntermediates/Video-Community/InstallationBuildProductsLocation/Applications/PC365.app
/appcenter-pre-build.sh (in target 'Video-Community' from project 'VideoApp')

** ARCHIVE FAILED **

##[error]Error: /usr/bin/xcodebuild failed with return code: 65

所以它以某种方式产生了这个脚本的副本。

这对我来说似乎很奇怪,因为脚本没有分配给任何目标并且是在 Xcode 之外创建的。

我想,问题出在某种脚本缓存上。我已经从存储库中删除 appcenter-pre-build.sh,推送,在 App Center 中构建(这次没有错误),然后再次添加脚本,推送并且它只是工作。