Azure devops can not publish Apk android

newbie here to azure DevOps trying to setup ci/cd for testing purposes on sample android app. I have following azure-pipelines.yml

    trigger:
- master

pool: default
variables:
  - name: 'apkFilePath'
    value: '**/*debug*.apk'

steps:
- task: Gradle@2
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleDebug'
- task: CopyFiles@2
  displayName: "Copy files"
  continueOnError: false
  inputs:
    Contents: ${apkFilePath}
    targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  continueOnError: false
  displayName: "Publish to azure"
  inputs:
     PathtoPublish: '$(Build.ArtifactStagingDirectory)'
     ArtifactName:   'debug'

when i run the pipeline i m getting warning In the publishBuildArtifacts step ##[warning]Directory '/Users/XXXX/Desktop/myagent/_work/2/a' is empty. Nothing will be added to build artifact 'debug'.

I am guessing files are not being copied to '$(Build.ArtifactStagingDirectory)' but could not wrap my head around why ?

any help would be apprecieated

Upvotes: 0

Views: 1571

Answers (1)

SauravDas-MT
SauravDas-MT

Reputation: 1444

I didn't found any mistake in the yaml file. The error which you are getting must be due to the apkFilePath. If you check the Copy File Task document by Microsoft, you will find that the Contents is the required file paths to include as part of the copy. and it supports multiple lines of match patterns as shown below.

  • * copies all files in the specified source folder.
  • ** copies all files in the specified source folder and all files in all sub-folders.
  • **\bin\** copies all files recursively from any bin folder.

Remember that the pattern is used to match only file paths, not folder paths. Try the following yaml snippet to copy the .apk file from source to the artifact directory.

- task: CopyFiles@2
  displayName: 'Copy Files'
  inputs:
    SourceFolder: 'MobileApp/SourceCode -Android' 
    Contents: '**/*.apk'
    TargetFolder: '$(build.artifactStagingDirectory)'

or

- task: CopyFiles@2
- displayName: 'Copy Files'
  inputs:
    SourceFolder: $(Build.SourcesDirectory) //optional
    contents: '**/*.debug.apk'
    targetFolder: '$(build.artifactStagingDirectory)'

The SourceFolder is the folder that contains the files you want to copy. If you leave it empty, the copying is done from the root folder of the repo (same as if you had specified $(Build.SourcesDirectory).

Check these Build an Android Mobile Application Using Azure DevOps and How to build and sign your Android application using Azure DevOps document for more information. Also check this similar issue posted in stack overflow for more understanding.

Upvotes: 2

Related Questions