Deploying Android apk to hockeyapp


#1

Anyone know the command to be used in circle.yml to deploy output of Android build (APK) to hockeyapp? I looked at the docs and forums but didn’t find a solution. Thanks!


#2

This circle.yml code should do the trick:

dependencies:
  pre:
    - sudo gem install shenzhen
test:
  override:
    - ./scripts/add-key.sh
    - ipa build -c Distribution
    - ./scripts/remove-key.sh
deployment:
  hockey:
    branch: master
    commands:
      - ipa distribute:hockeyapp -m "circleci build" --token $HOCKEYAPP_TOKEN

ref: http://mazyod.com/blog/2015/03/26/marry-circleci-to-hockey/


#3

Tried that but didn’t work. Ultimately ended up writing a custom deploy script that does curl upload to hockey. Thanks for the answer anyway!


#4

Sorry I wasn’t able to help. Would you be willing to share your script? It might be helpful to others.


#5

I also wasn’t able to use that method, and ended up rolling with my own script. Here’s what I did:

circle.yml:

deployment:
  develop:
    branch: develop
    commands:
      - ./deploy_dev.sh

deploy_dev.sh:

curl \
-F "status=2" \
-F "notify=0" \
-F "ipa=@AppName/build/outputs/apk/appname-dev-debug.apk" \
-H "X-HockeyAppToken: $HockeyAppToken" \
https://rink.hockeyapp.net/api/2/apps/$AndroidAppId_Dev/app_versions/upload

#6

@drazisil The script posted above by @dmaltsiniotis is exactly what I ended up writing.


#7

Where do you find the location of your apk on circleci?


#9

I want to upload specific builds ( verified builds) of circle ci on Hockey not all . How it can be automated with the help of above scripts.

Thanks in advance.


#10

Thanks to dmaltsiniotis for the script. I am able to successfully upload my multiple android apks simultaneously to hockey.
Here are the steps. Hope it will help others.

  1. First we need to get below parameter value :
    (a) Hockey app token - hockey api token which you can get from hockey dashboard
    (b) hockey app id- hockey app channel id to which you want to upload

  2. Add all above parameters as Environment variables in circle ci dashboard as below:
    HOCKEYAPP_TOKEN
    AndroidFirstAppId
    AndroidSecondAppId

  3. Go to your circle.yml file and add below code
    deployment:
    feature:
    branch: /deploy-.*/
    commands:

  4. add deploy_dev.sh file at the same place with circle.yml:

curl
-F “status=2”
-F “notify=1”
-F “ipa=@APK FULL PATH(projectname/build/outputs/apk/APK_NAME”
-H “X-HockeyAppToken: $HOCKEYAPP_TOKEN”
https://rink.hockeyapp.net/api/2/apps/$AndroidFirstAppId/app_versions/upload
curl
-F “status=2”
-F “notify=1”
-F “ipa=@APK FULL PATH(projectname/build/outputs/apk/APK_NAME”
-H “X-HockeyAppToken: $HOCKEYAPP_TOKEN”
https://rink.hockeyapp.net/api/2/apps/$AndroidSecondAppId/app_versions/upload

trigger build :slight_smile:

I have one query in this process. for now this deployment will trigger when there is specified branch name or tag. is there any method in which we can mention in commit message that deployment should be taken or not


#11

This thread helped me to setup both the circleci and hockeyapp for me and its working perfectly. But I wonder how I can send the build ID or the build number to hockey app from circleci as an extra information so that tester. Now I am not able to recognize which build was generated from which commit.


#12

-F "notes=$CIRCLE_BRANCH
-F “repository_url=$CIRCLE_REPOSITORY_URL”
-F “build_server_url=$CIRCLE_BUILD_URL”
-F “commit_sha=$CIRCLE_SHA1” \

This is how I figured out to pass on some kind of tags.


#15

Thanks halfer. Have provided formatted yaml file :slight_smile:


#16

Great stuff. Paste your YAML here - it looks like it does not validate. That’d need to be fixed and re-committed in your repo.


#18

You cannot run scripts directly unless they have an appropriate execute bit set, although it seems you have tried that, so it is odd that that did not work. However, you can make it easier just by calling them in a shell command:

sh ./deploy.sh

#19

Many thanks @halfer

my deploy script it running now. But I am getting error
#!/bin/bash -eo pipefail
sh ./deploy.sh
curl: (26) couldn’t open file “app/build/outputs/apk/app-debug.apk”
Exited with code 26

Below is my deploy.sh

curl \
-F "status=2" \
-F "notify=1" \
-F "ipa=@${2:-app/build/outputs/apk/debug/app-debug.apk}" \
-H "X-HockeyAppToken: <hockey-app-token>" \
https://rink.hockeyapp.net/api/2/apps/<app-id>/app_versions/upload

As mentioned in my previous post for 1 of 2 failing builds, 3 targets are executed as follows:

  1. Spin up Environment
  2. Checkout code
  3. Deploy to hockey app

"Since while running “Deploy to hockey app” build target was not run till time and hence app-debug should not be available.

Any idea how can I solve this? Is it expected behavior to have 2 builds running on Circle CI(I believe that could be because I am now using workflows and deploy is dependent on build)


#20

I am guessing this is created in your build job, and you are wanting to make use of it in your deploy job. By default, each job gets a clean build container, so your artefact will have gone. I suspect you will benefit from Workspaces to preserve this directory - see the manual.


#21

Ah, I just spotted why this did not work - it is in the wrong job. Any changes you make in a build job are not automatically preserved for other jobs in the same workflow. Although you could move this step to the other job (since you presumably do not need it for building) it is now redundant, so I would recommend removing it.


#22

Thanks @halfer for all your help. I have deployed my build successfully. :slight_smile:


#23

Excellent, and you’re welcome. Please do explain how you did so, for the benefit of future readers :slightly_smiling_face:.


#25

Re posting working yaml

version: 2
references:
  save_workspace_artifacts: &save_workspace_artifacts
    store_artifacts:
      path: outputs/outputs/apk
  attach_workspace_artifacts: &attach_workspace_artifacts
    attach_workspace:
      at: outputs
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-25-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
         name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
         command: sudo chmod +x ./gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
#      - run:
#          name: Run Tests
#          command: ./gradlew lint test
      - run:
          name: Build Code
          command: ./gradlew assembleDebug
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_artifacts:
          path: app/build/outputs
          destination: apk
      - persist_to_workspace:
          root: app/build
          paths:
            - outputs
#      - store_test_results:
#          path: app/build/test-results
      # See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples
      
  deploy:
    docker:
      - image: circleci/node:latest
    steps:
      - checkout
      - *attach_workspace_artifacts
      # storing to be visible on api as an outcome of the last build
      - *save_workspace_artifacts
      - run:
          name: Deploy to hockey app
          command: sh ./deploy.sh
		  
workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master