I've created an Azure DevOps pipeline script for my Android project. The build is successful, but when I try to upload artifacts, it fails with the message "no artifacts found."
My azure-pipelines.yml is as follows:
trigger:
- main
pool:
vmImage: 'windows-latest'
stages:
- stage: Build
displayName: 'Build APK'
jobs:
- job: BuildDebug
displayName: 'Build Debug APK'
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
- script: |
echo "Checking Java version"
java -version
displayName: 'Check Java Version'
- script: |
echo "Running Gradle task: assembleDebug"
java -version
./gradlew clean
./gradlew assembleDebug
displayName: 'Run Gradle Build'
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: app\build\outputs\apk
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)\app\build\outputs\apk\debug'
ArtifactName: 'apk'
publishLocation: 'Container'
Error:
##[error]Error: Not found SourceFolder: D:\a\1\s\app\build\outputs\apk
I've tried adding the tree command to check the build folder, but it isn't created.
I've tried adding tree
command to see if build folder is being created after gradle build
, but it isnt.
- script: |
echo "Tree"
tree
tree $(Build.ArtifactStagingDirectory)
displayName: 'Tree'
I can reproduce the same error with your yaml:
This is because the gradle assembleDebug
command didn't generate the apk in the folder app\build\outputs\apk
. I changed the copy task below to find all apk but no files are found:
- task: CopyFiles@2
inputs:
contents: '**/*.apk'
targetFolder: '$(build.artifactStagingDirectory)'
To fix the error, you can use Gradle@2
instead for the build.
- script: |
echo "Running Gradle task: assembleDebug"
java -version
./gradlew clean
# ./gradlew assembleDebug # comment the task.
displayName: 'Run Gradle Build'
- task: Gradle@2 # use task with assembleDebug here
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'assembleDebug'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
sonarQubeRunAnalysis: false
spotBugsAnalysis: false
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: 'app\build\outputs\apk'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
The apk files are found and copied(without debug folder in path):