Android Gitlab CI/CD脚本

# 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

复制代码

你可能感兴趣的:(Android Gitlab CI/CD脚本)