0

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'
4
  • What is the output of CopyFiles@2 task? Try adding a task to list files in app\build\outputs\apk folder, before publishing the artifacts. Commented Jul 6 at 16:04
  • @RuiJarimba `##[error]Error: Not found SourceFolder: D:\a\1\s\app\build\outputs\apk ' I am getting this error Commented Jul 6 at 16:12
  • Run the pipeline in diagnostics mode and try to understand where are the files generated by task Run Gradle Build. Commented Jul 6 at 16:49
  • You can use tree /a /f $(Build.SourcesDirectory) command to check the files before and after the build task. This command will display the names of the files in each directory. Commented Jul 8 at 8:59

1 Answer 1

0

I can reproduce the same error with your yaml:

enter image description here

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)'

enter image description here

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):

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.