Android Gitlab CI/CD指令碼

醉眼笑驚鴻發表於2018-09-05
# This file is a template, and might need editing before it works on your project.
# Read more about this script on this blog post https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/, by Greyson Parrelli
image: openjdk:8-jdk

variables:
  SOURCE_FILE_PATH: "./app/build/outputs/apk/*"
  # 修改生成的apk存放路徑
  TARGET_FILE_PATH: "/home/android-apk/ProjectName/app/"

before_script:
  - export ANDROID_HOME=/opt/android_sdk/
  - export PATH=$PATH:/opt/android_sdk/platform-tools/
  - chmod +x ./gradlew

# 理解為階段,階段的執行順序
stages:
  - build
  - assemble
  - deploy

# 日常 master修改,執行編譯
# 觸發條件:push master 執行任務
job_build:
  stage: build
  # 所需執行的指令碼
  script:
    - ./gradlew clean
    - ./gradlew assembleRelease
  only:
    - master

#================================================================
# release版本打包
# 觸發條件:打git tag 分支名稱 ,正則匹配 “V” 開頭,符合則執行,如V1.0.0
job_assemble:
  stage: assemble
  # 所需執行的指令碼
  script:
    - ./gradlew clean
    - ./gradlew app:assembleRelease
    - 'mkdir -p ${TARGET_FILE_PATH}/assemble/'
    - 'cp -fRap ${SOURCE_FILE_PATH} ${TARGET_FILE_PATH}/assemble/'
  artifacts:
      paths:
        - ./app/build/outputs/
  only:
    - /^V.*$/
  except:
      - branches

複製程式碼
Build Job - job_build 
=================================
Tag list: 
Only policy: refs, master 
Except policy: 
Environment: 
When: on_success
複製程式碼
Assemble Job - job_assemble
=================================
Tag list: 
Only policy: refs, /^V.*$/ 
Except policy: refs, branches 
Environment: 
When: on_success

複製程式碼

相關文章