androidcontinuous-integrationbitbucketdevopsbitbucket-pipelines

How to locate apk file using bitbucket-pipelines?


I'm using BitBucket-pipelines for Android CI. I'm trying to export the artifact (generated apk) to the downloads section of the project.

My bitbucket-pipelines.yml is as follows, but it can't locate the apk file

image: openjdk:8

pipelines:
default:
- step:
    caches:
      - gradle
      - android-sdk

    script:
      # Download and unzip android sdk
      - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
      - unzip -o -qq android-sdk.zip -d android-sdk

      # Define Android Home and add PATHs
      - export ANDROID_HOME="/opt/atlassian/pipelines/agent/build/android-sdk"
      - export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

      # Download packages.
      - yes | sdkmanager "platform-tools"
      - yes | sdkmanager "platforms;android-27"
      - yes | sdkmanager "build-tools;27.0.3"
      - yes | sdkmanager "extras;android;m2repository"
      - yes | sdkmanager "extras;google;m2repository"
      - yes | sdkmanager "extras;google;instantapps"
      - yes | sdkmanager --licenses

      # Build apk
      - chmod a+x ./gradlew
      - ./gradlew assembleDebug

      # Saving artifact
      - curl -X POST "https://${BB_AUTH_STRING}@api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"**/*.apk"


definitions:
  caches:
     android-sdk: android-sdk

The issue is in

- curl -X POST "https://${BB_AUTH_STRING}@api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"**/*.apk"

I've also tried the following instead of **/*.apk

./app/build/outputs/apk/*.apk

But so far, nothing can locate the apk.

Has anyone faced this issue before? I'm just getting into CI with Android and would be grateful if someone could help.


Solution

  • I was able to resolve the issue by adding an artifacts tag after the build step. Then to publish the apk file I had to point to the specific file (path respective to the parent folder).

    My bitbucket-pipelines.yml file is as follows now.

    image: openjdk:8
    
    pipelines:
      default:
        - step:
          caches:
            - gradle
            - android-sdk
    
          script:
            # Download and unzip android sdk
            - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
            - unzip -o -qq android-sdk.zip -d android-sdk
    
            # Define Android Home and add PATHs
            - export ANDROID_HOME="/opt/atlassian/pipelines/agent/build/android-sdk"
            - export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
    
            # Download packages.
            - yes | sdkmanager "platform-tools"
            - yes | sdkmanager "platforms;android-27"
            - yes | sdkmanager "build-tools;27.0.3"
            - yes | sdkmanager "extras;android;m2repository"
            - yes | sdkmanager "extras;google;m2repository"
            - yes | sdkmanager "extras;google;instantapps"
            - yes | sdkmanager --licenses
    
            # Build apk
            - chmod a+x ./gradlew
            - ./gradlew assembleDebug
    
          artifacts:
            - app/build/outputs/apk/debug/*.apk
    
      - step:
         script:
            # Saving artifact
            - curl -X POST "https://${BB_AUTH_STRING}@api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"app/build/outputs/apk/debug/app-debug.apk"
    
    
    definitions:
        caches:
            android-sdk: android-sdk