我一直在研究这个问题,我当前的 Yaml 管道脚本如下所示:
variables:
- group: configurationAppCenterAppSlug
- group: configurationPipeline
parameters:
- name: schemeName
displayName: 'Choose environment:'
type: string
default: stageCasa
values:
- stageCasa
- stageCz
- stagePsk
- stageSk
- stageRo
trigger:
- casa-redesign
pool:
vmImage: 'macos-latest'
steps:
- checkout: self
displayName: 'Update repo files'
fetchDepth: 1
fetchTags: false
lfs: false
clean: false
- script: |
echo "Checking for Java 11"
if /usr/libexec/java_home -v 11 >/dev/null 2>&1; then
echo "Java 11 found"
JAVA_HOME=$(/usr/libexec/java_home -v 11)
echo "Setting JAVA_HOME to $JAVA_HOME"
else
echo "Java 11 not found, installing via Homebrew"
brew install openjdk@11
brew link --force --overwrite openjdk@11
JAVA_HOME=$(/usr/libexec/java_home -v 11)
echo "Setting JAVA_HOME to $JAVA_HOME"
fi
echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME"
displayName: 'Check for Java 11 and install if not present'
- script: |
echo "JAVA_HOME is set to: $JAVA_HOME"
java -version
displayName: 'Verify Java Installation'
- task: Gradle@2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: "bundle${{ parameters.schemeName }}Release"
env:
JAVA_HOME: $(JAVA_HOME)
- script: |
if [ -f "$(System.DefaultWorkingDirectory)/app/build/outputs/bundle/stageCasaRelease/app-stage-casa-release.aab" ]; then
cp "$(System.DefaultWorkingDirectory)/app/build/outputs/bundle/stageCasaRelease/app-stage-casa-release.aab" "$(Build.ArtifactStagingDirectory)/app-stage-casa-release.aab"
echo "AAB file copied successfully."
else
echo "AAB file does not exist."
fi
displayName: 'Copy AAB file to Artifact Staging Directory'
- task: AppCenterDistribute@3
inputs:
serverEndpoint: 'AppCenter Service'
# appSlug: 'FEG/Vegas-CASA-Stage-1'
appSlug: '$(${{ parameters.schemeName }}_appSlug)'
appFile: '$(Build.ArtifactStagingDirectory)/app-stage-casa-release.aab'
releaseNotesOption: 'input'
releaseNotesInput: '- empty'
让我困扰的是,当我运行这个管道时,它有时会起作用。它构建 aab 文件并将其推送到 Appcenter。 其他时候它会失败并出现如下错误:
AppCenterDistribute
View raw log
Starting: AppCenterDistribute
==============================================================================
Task : App Center distribute
Description : Distribute app builds to testers and users via Visual Studio App Center
Version : 3.232.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/app-center-distribute
==============================================================================
##[error]Error: Cannot find any file based on /Users/runner/work/1/a/app-stage-casa-release.aab.
Finishing: AppCenterDistribute
这让我很困惑,因为有时有效,有时无效。我哪里错了,有什么想法吗?我觉得我已经非常接近解决方案了,就像缺少一块拼图一样......谢谢
感谢您@Ziyang Liu-MSFT的评论。
您可以使用下面的Azure Yaml管道,其中利用
if else statements
来检查AAB文件是否存在:-
variables:
- group: configurationAppCenterAppSlug
- group: configurationPipeline
parameters:
- name: schemeName
displayName: 'Choose environment:'
type: string
default: stageCasa
values:
- stageCasa
- stageCz
- stagePsk
- stageSk
- stageRo
trigger:
- casa-redesign
pool:
vmImage: 'macos-latest'
steps:
- checkout: self
displayName: 'Update repo files'
fetchDepth: 1
fetchTags: false
lfs: false
clean: false
- script: |
echo "Checking for Java 11"
if /usr/libexec/java_home -v 11 >/dev/null 2>&1; then
echo "Java 11 found"
JAVA_HOME=$(/usr/libexec/java_home -v 11)
echo "Setting JAVA_HOME to $JAVA_HOME"
else
echo "Java 11 not found, installing via Homebrew"
brew install openjdk@11
brew link --force --overwrite openjdk@11
JAVA_HOME=$(/usr/libexec/java_home -v 11)
echo "Setting JAVA_HOME to $JAVA_HOME"
fi
echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME"
displayName: 'Check for Java 11 and install if not present'
- script: |
echo "JAVA_HOME is set to: $JAVA_HOME"
java -version
displayName: 'Verify Java Installation'
- task: Gradle@2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: "bundle${{ parameters.schemeName }}Release"
env:
JAVA_HOME: $(JAVA_HOME)
- script: |
if [ -f "$(Build.SourcesDirectory)/app/build/outputs/bundle/${{ parameters.schemeName }}Release/app-${{ parameters.schemeName }}-release.aab" ]; then
cp "$(Build.SourcesDirectory)/app/build/outputs/bundle/${{ parameters.schemeName }}Release/app-${{ parameters.schemeName }}-release.aab" "$(Build.ArtifactStagingDirectory)/app-${{ parameters.schemeName }}-release.aab"
echo "AAB file copied successfully."
else
echo "AAB file does not exist."
exit 1
fi
displayName: 'Copy AAB file to Artifact Staging Directory'
- task: AppCenterDistribute@3
inputs:
serverEndpoint: 'AppCenter Service'
appSlug: '$(appSlug)' # Make sure the correct variable name is used here
appFile: '$(Build.ArtifactStagingDirectory)/app-${{ parameters.schemeName }}-release.aab'
releaseNotesOption: 'input'
releaseNotesInput: '- empty'