美文网首页
CICD_中Jenkins关于android自动构建

CICD_中Jenkins关于android自动构建

作者: 钓小鱼的猫 | 来源:发表于2019-11-07 19:19 被阅读0次

1.配置环境

jenkins_>系统管理->系统设置
配置AndroidSDK


image.png

1.1jenkins_>全局工具配置

配置JDK

image.png

配置Git Grdle

image.png

代码中gradle环境变量配置

def apiEnvironment = API_ENVIRONMENT ? API_ENVIRONMENT : project.API_ENVIRONMENT

static def buildTime() {
    def date = new Date()
    def formattedDate = date.format('MMdd_HHmm')
    return formattedDate
}

apply plugin: PresetResourcePlugin

presetExt {
    def baseUrl
    switch (apiEnvironment) {
        case "LOCAL":
            baseUrl = "http://192.168.60.122:7002/"
            break
        case "DEV":
            baseUrl = "https://dev1-xxxx.com/"
            break
        case "DEV2":
            baseUrl = "https://test1-xxx.com/"
            break
        case "UAT":
            baseUrl = "https://uat-xxxx.com/"
            break
        case "ONLINE":
            baseUrl = "https://app-xxxx.com/"
            break
        default:
            baseUrl = "https://app_xxxx.com/"
            break
    }
image.png

其中assembleMeizu为gradle设置的渠道包
API_ENVIRONAMET=DEV2设置环境变量

image.png

2.配置commit message信息

image.png

2.2配置build脚本

image.png

3.配置执行shell

#编译完成,开始上传蒲公英
apkname=` ls -lt ${WORKSPACE}/android/app/build/outputs/apk/meizu/release/ | grep gyxxx_ | head -n 1 |awk '{print $9}'`
curl -F "file=@${WORKSPACE}/android/app/build/outputs/apk/meizu/release/$apkname" -F "uKey=xxx" -F "_api_key=xxx" -F "updateDescription=测试环境android测试包,${apkname},${SCM_CHANGELOG},蒲公英打包" http://www.pgyer.com/apiv1/app/upload
#打包完成


source /root/.bashrc

echo 'ok!'
echo `date +%Y-%m-%d-%H-%M`
echo $JOB_NAME
tag=${GIT_COMMIT:0-7}-Android_auto_test-`date +%Y-%m-%d-%H-%M`
echo $tag



rm -f jenkins.conf
echo Tag=$tag >>jenkins.conf
echo RepoName=$gitlabSourceRepoName >>jenkins.conf
echo UserName=$gitlabUserName >>jenkins.conf
echo Message=${SCM_CHANGELOG}>>jenkins.conf
echo tips="测试环境打包完成">>jenkins.conf


/usr/bin/python /app/local/jenkins/jenkins.py


#触发钉钉推送
curl 'https://oapi.dingtalk.com/robot/send?access_token=4xxxxxfaf296910dddbf12761b8487ce568bdbf5b62d5302fb94fe39ec5d72' \
      -H 'Content-Type: application/json' \
      -d "{
            \"msgtype\": \"text\",
            \"text\": {
              \"content\": \"Tag=${tag},\nRepoName=${gitlabSourceRepoName},\n UserName=${gitlabUserName},\n Message=${SCM_CHANGELOG},\n tips=Android测试环境打包完成\"
            }
          }"


# 上传 apk 到 oss

accessKeyId=xxxxx
ENDPOINT="https://oss-cn-shanghai.aliyuncs.com"
DIR=${WORKSPACE}/android/app/build/outputs/apk/meizu/release
OSS_PATH="oss://gymbo-dev-public/app/android/test"
ossutil cp ${DIR} ${OSS_PATH} --include "*.apk" -r -f --endpoint=${ENDPOINT} --access-key-id=${accessKeyId} --access-key-secret=${accessKeySecret} --loglevel=debug

4.配置钉钉推送

image.png

相关文章

网友评论

      本文标题:CICD_中Jenkins关于android自动构建

      本文链接:https://www.haomeiwen.com/subject/zoavbctx.html