当前位置: 首页 > news >正文

Android配置GitLab CI/CD持续集成,Shell版本的gitlab-runner,FastLane执行,上传蒲公英

mac环境下,

首选需要安装gitlab-runner和fastlane

brew install gitlab-runner

brew install fastlane

安装完成,来到我们在gitlab下新建的Android项目,我们开始创建gitlab-runner

1、创建runner

点开runner,点击新建runner

选择macos,自定义一个标签,把运行未打标签的作业也够选上,点击创建runner

然后来到这个页面,开始在终端挨个执行命令

执行命令,一定要选择shell,可以看到这时候就创建runner成功了

testrunner就是这个runner的名字

gitlab-runner list  

执行这个命令可以看到电脑上所有的runner

gitlab-runner status  可以查看gitlab-runner的状态

如果状态不在线,可以调用gitlab-runner  install 命令  再调用gitlab-runner  start

2、fastlane

cd到项目跟目录下,使用fastlane init

根目录下就会创建fastlane文件夹

我们要写的代码都在Fastfile中

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
## Uncomment the line if you want fastlane to automatically update itself
# update_fastlanedefault_platform(:android)
APK_TIME = Time.now.strftime("%Y%m%d")
app_versionName  = "1.0.0"BUILD_NAME = ""
# OUTPUT_NAME_PATCH = "#{BUILD_NAME}_#{PLIST_INFO_VERSION}_#{APK_TIME}"
platform :android dodesc "给测试用单渠道cnrmall_official的包"puts "APK_TIME=== #{APK_TIME}"channel = "cnrmall_official"lane :debug_cnrmall_official doBUILD_NAME = "android_Debug_#{channel}"gradle(task: "clean assemble#{channel}",build_type: "Debug")mk_cp_apkpgyer_upload(channel: "#{channel}")end#debug全渠道包
lane :debug dochannel = "cnrmall_official"BUILD_NAME = "android_Debug"gradle(task: "clean assemble",build_type: "Debug")pgyer_upload(channel: "#{channel}")end#release全渠道包lane :release dochannel = "cnrmall_official"BUILD_NAME = "android_Release"gradle(task: "clean assemble",build_type: "Release")pgyer_upload(channel: "#{channel}")end# 执行创建文件夹 copy apk 到最外面目录
lane :mk_cp_apk doputs "mk out_apk cp apk"gradle(task: "customBuild")endlane :get_version doputs "Update Android version in build.gradle"app_version = gradle(task: "getVersionName")# 获取版本号
#       puts "app_version:#{versionCode}"enddesc "Submit a new Beta Build to Crashlytics Beta"lane :beta dogradle(task: "clean assembleRelease")crashlytics# sh "your_script.sh"# You can also use other beta testing services hereenddesc "Deploy a new version to the Google Play"lane :deploy dogradle(task: "clean assembleRelease")upload_to_play_storeend##上传蒲公英lane :pgyer_upload do |option|sh 'ls'pyg_get_channel = option[:channel]puts "上传蒲公英channel= #{pyg_get_channel}"
#      ENV['outPutPath'] = '../app/build/outputs/apk/'+"#{pyg_get_channel}"+"/debug/cnrmall_"+"#{APK_TIME}"+"_"+"#{app_versionName}"+"_"+"#{pyg_get_channel}"+".apk"ENV['outPutPath'] = '../out_apk/cnrmall_'+"#{APK_TIME}"+"_"+"#{app_versionName}"+"_"+"#{pyg_get_channel}"+".apk"puts "outPutPath路径- #{ENV['outPutPath']}"
#      ENV['outPutPath'] = '../app/build/outputs/apk/option/debug/cnrmall_#{APK_TIME}_1.0.0_cnrmall_official.apk'
#      sh "open ../app/build/outputs/apk/debug/"sh "./pgyer_upload.sh  -k 4df7384110457be3f5bce0c391ef1cd3  #{ENV['outPutPath']} "endend

上传蒲公英脚本

#!/bin/bash
#
# 通过shell脚本来实现将本地app文件通过API上传到蒲公英
# https://www.pgyer.com/doc/view/api#fastUploadApp
## Display log. 1=enable, 0=disable
LOG_ENABLE=1printHelp() {echo "Usage: $0 -k <api_key> [OPTION]... file"echo "Upload iOS or Android app package file to PGYER."echo "Example: $0 -k xxxxxxxxxxxxxxx /data/app.apk"echo ""echo "Description:"echo "  -k api_key                       (required) api key from PGYER"echo "  -t buildInstallType              build install type, 1=public, 2=password, 3=invite"echo "  -p buildPassword                 build password, required if buildInstallType=2"echo "  -d buildUpdateDescription        build update description"echo "  -e buildInstallDate              build install date, 1=buildInstallStartDate~buildInstallEndDate, 2=forever"echo "  -s buildInstallStartDate         build install start date, format: yyyy-MM-dd"echo "  -e buildInstallEndDate           build install end date, format: yyyy-MM-dd"echo "  -c buildChannelShortcut          build channel shortcut"echo "  -h help                          show this help"echo ""echo "Report bugs to: <https://github.com/PGYER/pgyer_api_example/issues>" echo "Project home page: <https://github.com/PGYER/pgyer_api_example>" exit 1
}while getopts 'k:t:p:d:s:e:c:h' OPT; docase $OPT ink) api_key="$OPTARG";;t) buildInstallType="$OPTARG";;p) buildPassword="$OPTARG";;d) buildUpdateDescription="$OPTARG";;e) buildInstallDate="$OPTARG";;s) buildInstallStartDate="$OPTARG";;e) buildInstallEndDate="$OPTARG";;c) buildChannelShortcut="$OPTARG";;?) printHelp;;esac
doneshift $(($OPTIND - 1))
readonly file=$1# check api_key exists
if [ -z "$api_key" ]; thenecho "api_key is empty"printHelp
fi# check file exists
if [ ! -f "$file" ]; thenecho "file not exists"printHelp
fi# check ext supported
buildType=${file##*.}
if [ "$buildType" != "" ] && [ "$buildType" != "apk" ]; thenecho "file ext is not supported"printHelp
fi# ---------------------------------------------------------------
# functions
# ---------------------------------------------------------------log() {[ $LOG_ENABLE -eq 1 ]  && echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"
}logTitle() {log "-------------------------------- $* --------------------------------"
}execCommand() {log "$@"result=$(eval $@)
}# ---------------------------------------------------------------
# 获取上传凭证
# ---------------------------------------------------------------logTitle "获取凭证"command="curl -s"
[ -n "$api_key" ]                && command="${command} --form-string '_api_key=${api_key}'";
[ -n "$buildType" ]              && command="${command} --form-string 'buildType=${buildType}'";
[ -n "$buildInstallType" ]       && command="${command} --form-string 'buildInstallType=${buildInstallType}'";
[ -n "$buildPassword" ]          && command="${command} --form-string 'buildPassword=${buildPassword}'";
[ -n "$buildUpdateDescription" ] && command="${command} --form-string $'buildUpdateDescription=${buildUpdateDescription}'";
[ -n "$buildInstallDate" ]       && command="${command} --form-string 'buildInstallDate=${buildInstallDate}'";
[ -n "$buildInstallStartDate" ]  && command="${command} --form-string 'buildInstallStartDate=${buildInstallStartDate}'";
[ -n "$buildInstallEndDate" ]    && command="${command} --form-string 'buildInstallEndDate=${buildInstallEndDate}'";
[ -n "$buildChannelShortcut" ]   && command="${command} --form-string 'buildChannelShortcut=${buildChannelShortcut}'";
command="${command} http://www.pgyer.com/apiv2/app/getCOSToken";
execCommand $command[[ "${result}" =~ \"endpoint\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && endpoint=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'`
[[ "${result}" =~ \"key\":\"([\.a-z0-9]+)\" ]] && key=`echo ${BASH_REMATCH[1]}`
[[ "${result}" =~ \"signature\":\"([\=\&\_\;A-Za-z0-9\-]+)\" ]] && signature=`echo ${BASH_REMATCH[1]}`
[[ "${result}" =~ \"x-cos-security-token\":\"([\_A-Za-z0-9\-]+)\" ]] && x_cos_security_token=`echo ${BASH_REMATCH[1]}`if [ -z "$key" ] || [ -z "$signature" ] || [ -z "$x_cos_security_token" ] || [ -z "$endpoint" ]; thenlog "get upload token failed"exit 1
fi# ---------------------------------------------------------------
# 上传文件
# ---------------------------------------------------------------logTitle "上传文件"file_name=${file##*/}execCommand "curl --progress-bar -o /dev/null -w '%{http_code}' \
--form-string 'key=${key}' \
--form-string 'signature=${signature}' \
--form-string 'x-cos-security-token=${x_cos_security_token}' \
--form-string 'x-cos-meta-file-name=${file_name}' \
-F 'file=@${file}' ${endpoint}"
if [ $result -ne 204 ]; then # if http code != 204, upload failedlog "Upload failed"exit 1
fi# ---------------------------------------------------------------
# 检查结果
# ---------------------------------------------------------------logTitle "检查结果"# 获取 .apk 文件所在的目录
Directory=$(dirname "$file")echo "获取 .apk 文件所在的目录 $Directory"jsonFilePath="$Directory/result.json"
qrCodeFilePath="$Directory/qr_code.png"for i in {1..60}; doexecCommand "curl -s http://www.pgyer.com/apiv2/app/buildInfo?_api_key=${api_key}\&buildKey=${key}"[[ "${result}" =~ \"code\":([0-9]+) ]] && code=`echo ${BASH_REMATCH[1]}`if [ $code -eq 0 ]; thenecho $resultecho $result > "$jsonFilePath"  # 将 JSON 保存到文件# 提取 buildQRCodeURL 的值
#        qrCodeURL=$(jq -r '.data.buildQRCodeURL' <<< "$result")qrCodeURL=$(echo "$result" | grep -o '"buildQRCodeURL":"[^"]*' | cut -d '"' -f 4 | sed 's/\\//g')# 使用 curl 下载并保存 QR Code 文件echo "Downloading QR Code from: $qrCodeURL"#         curl -s "$qrCodeURL" -o "$qrCodeFilePath"curl --location-trusted -o "$qrCodeFilePath" "$qrCodeURL"echo "curl Result: $curlResult"breakelsesleep 1fi
done

.gitlab-ci.yml,只需要写上执行哪个fastlane即可 ,debug_cnrmall_official是fastlane名字

在Android studio中的Terminal中,也可以使用命令去执行某一个fastlane

如:fastlane lane:debug_cnrmall_official

stages:- buildjob:stage: buildscript:- echo "开始打包4"- ls -a# - ./build.sh- fastlane debug_cnrmall_officialartifacts:paths:- out_apk/*

项目跟目录的build.gradle文件中,还自定义了一个task

因为Android默认打包完的apk位置太深了,所以把它复制到外面一点,方便测试拿到

cnrmallshop_ci_2.0是项目名 out_apk是创建的文件夹
task customBuild(type: Exec) {def date = new SimpleDateFormat("yyyyMMdd").format(new Date())def versionName = rootProject.android.versionNamecommandLine 'sh','-c','mkdir -p ../cnrmallshop_ci_2.0/out_apk && cp app/build/outputs/apk/cnrmall_official/debug/cnrmall_'+date+'_'+versionName+'_cnrmall_official.apk ../cnrmallshop_ci_2.0/out_apk/cnrmall_'+date+'_'+versionName+'_cnrmall_official.apk'
}

最后可以在流水线上中看到构建成功的流水线,可以点击下载按钮下载产物

​​​​​​​

产物中有apk有二维码

相关文章:

Android配置GitLab CI/CD持续集成,Shell版本的gitlab-runner,FastLane执行,上传蒲公英

mac环境下&#xff0c; 首选需要安装gitlab-runner和fastlane brew install gitlab-runner brew install fastlane 安装完成&#xff0c;来到我们在gitlab下新建的Android项目&#xff0c;我们开始创建gitlab-runner 1、创建runner 点开runner&#xff0c;点击新建runner …...

算法提升——LeetCode383场周赛总结

周赛题目 边界上的蚂蚁 边界上有一只蚂蚁&#xff0c;它有时向左走&#xff0c;有时向右走。 给你一个非零整数数组nums。蚂蚁会按顺序读取nums中的元素&#xff0c;从第一个元素开始直到结束。每一步&#xff0c;蚂蚁会根据当前元素的值移动&#xff1a; 如果nums[i]<0…...

(delphi11最新学习资料) Object Pascal 学习笔记---第4章第2.1节( 带结果的Exit例程)

4.2.1 带结果的Exit例程 ​ 我们已经看到&#xff0c;从函数中返回结果所使用的语法与 C 语言家族的语法截然不同。不仅语法不同&#xff0c;行为也不同。为结果&#xff08;或函数名&#xff09;赋值并不像return语句那样终止函数。Object Pascal 开发人员经常利用这一特性&a…...

vuecli3 执行 npm run build 打包命令报错:TypeError: file.split is not a function

问题 今天有个项目在打包的时候遇到了一个问题&#xff0c;就是执行 npm run build 命令的时候报错了&#xff0c;如下&#xff1a; 解决 我排查了一下&#xff0c;模拟代码如下&#xff1a;在打包的时候用了 MinChunkSizePlugin const webpack require("webpack"…...

【Java 数据结构】对象的比较

Java中对象的比较 1. PriorityQueue中插入对象2. 元素的比较2.1 基本类型的比较2.2 对象比较的问题 3. 对象的比较3.1 覆写基类的equals3.2 基于Comparble接口类的比较3.3 基于比较器比较3.4 三种方式对比 4. 集合框架中PriorityQueue的比较方式5. 使用PriorityQueue创建大小堆…...

2024 Google Chrome 浏览器回退安装旧版本

2024 Google Chrome 浏览器回退安装旧版本 查看当前谷歌版本备份浏览器数据卸载浏览器双击重新安装旧版本浏览器 查看当前谷歌版本 详细参考&#xff1a;参考 笔记&#xff1a;最近谷歌浏览器更新后&#xff0c;用着总感觉别扭&#xff1a;不习惯 备份浏览器数据 &#xff…...

将数组中的各字符串都调整为指定长度调整原则:多删(删右侧多出的)少补(左侧补数字0)numpy.char.zfill()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 将数组中的各字符串 都调整为指定长度 调整原则&#xff1a; 多删&#xff08;删右侧多出的&#xff09; 少补&#xff08;左侧补数字0&#xff09; numpy.char.zfill() [太阳]选择题 请问以…...

算法题目题单——图论

简介 本文为自己做的一部分图论题目&#xff0c;作为题单列出&#xff0c;持续更新。 题单由题目链接和题解两部分组成&#xff0c;题解部分提供简洁题意&#xff0c;代码仓库&#xff1a;Kaiser-Yang/OJProblems。 对于同一个一级标题下的题目&#xff0c;题目难度尽可能做…...

Maven提示Failure to find com.oracle:ojdbc14:jar:10.2.0.4.0

目录 问题 解决方案 1、下载oracle的驱动jar包 2、安装到本地仓库 3、检查本地仓库是否成功安装 4、Maven先clean &#xff0c;再install。 问题 项目引入Oracle依赖后报错&#xff0c;显示为红色。 解决方案 1、下载oracle的驱动jar包 首先我们要去下载一个oracle的…...

深度学习的数据集制作、标注、处理相关软件

制作深度学习数据集通常涉及数据的采集、标注和预处理等步骤。以下是一些可用于制作和处理深度学习数据集的软件工具&#xff0c;以及它们的详细介绍&#xff1a; 数据采集和生成 Web爬虫工具 (如 Scrapy, Beautiful Soup) 描述&#xff1a;这些工具可以帮助你从网上自动抓取和…...

点击按钮打开自定义iframe弹窗

1、效果 点击按钮打开弹窗&#xff1a; 打开弹窗后&#xff1a; 2、代码 <!DOCTYPE html> <html><head><title>iframe弹窗</title><style>/* 使用媒体查询来实现响应式设计 */media (min-width: 768px) {.popup {width: 80%; /* 设置…...

LeetCode977 有序数组的平方

暴力解法是平方之后排序复杂度是nnlogn 优化解法是双指针i&#xff0c;j&#xff0c;i放数组首元素位置&#xff0c;j放数组末尾&#xff0c;每次比较i和j位置的数组元素大小&#xff0c;然后挑一个大的放在新的数组元素的指定末尾位置上。 当原始数组nums第一个元素大于零时&a…...

Windows自动化实现:系统通知和任务栏图标自定义

文章目录 Windows自动化的三个小工具系统通知任务栏图标使用pystray实现使用infi.systray实现 Windows自动化的三个小工具 系统通知 import win10toastwin10toast.ToastNotifier().show_toast("eee", "休息一下", icon_path"icon.ico", durati…...

Spring | Spring的“数据库开发“ (Srping JDBC)

目录&#xff1a; Spring JDBC1.Spring JDBC的核心类 ( JdbcTemplate类 )2.Srping JDBC 的配置3.JdbcTemplate类的“常用方法”execute( )&#xff1a;直接执行“sql语句”&#xff0c;没有返回值update( ) &#xff1a;“增删改”&#xff0c;返回 “影响的行数”query( ) : “…...

面试八股文(2)

文章目录 1.ArrayList和LinkedList区别2.HashMap和HashTable区别3.线程的创建方式4.Java中异常处理5.Java序列化中某些字段不想进行序列化&#xff1f;6.Java序列化7.静态方法和实例方法8.List、Set、Map三者区别9.ArrayList和Vector区别10.HashMap和HashSet区别 1.ArrayList和…...

记elasticsearch CPU负载100%问题

记elasticsearch CPU负载100%问题 环境&#xff1a;问题表现&#xff1a;初步排查&#xff1a;日志查询hot_thread 深入查询当前elasticsearch正在运行的Task查看Task详情解决问题对导致问题的原因的几个猜测问题复现&#xff1a;导致问题的原因。json导入规则问题json导入规则…...

回归预测 | Matlab实现OOA-CNN-LSTM-Attention鱼鹰算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制)

回归预测 | Matlab实现OOA-CNN-LSTM-Attention鱼鹰算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&#xff09; 目录 回归预测 | Matlab实现OOA-CNN-LSTM-Attention鱼鹰算法优化卷积长短期记忆网络注意力多变量回归预测&#xff08;SE注意力机制&…...

PyTorch、NCNN、CV::Mat三者张量的shape

目录 一、PyTorch二、NCNN三、CV::Mat 一、PyTorch 在 PyTorch 中&#xff0c;张量&#xff08;Tensor&#xff09;的形状通常按照 (N, C, H, W) 的顺序排列&#xff0c;其中&#xff1a; N 是批量大小&#xff08;batch size&#xff09; C 是通道数&#xff08;channel numb…...

社交平台内容创作未来会有哪些方向?

内容为王的时代下&#xff0c;企业如果想要通过社交平台占据用户心智&#xff0c;可以找到适合自己的内容营销策略&#xff0c;好的内容能够与消费者建立信任关系&#xff0c;今天 媒介盒子就来和大家聊聊&#xff1a;社交平台内容创作的方向。 一、 内容逐渐细分 相比于原来…...

MySQL温故篇(一)SQL语句基础

一、SQL语句基础 1、SQL语言分类 DDL&#xff1a;数据定义语言 DCL&#xff1a;数据控制语言 DML&#xff1a;数据操作语言 DQL&#xff1a;数据的查询语言 2、数据类型 3、字符类型 char(11) &#xff1a; 定长 的字符串类型,在存储字符串时&#xff0c;最大字符长度11个&a…...

jEasyUI 自定义对话框

jEasyUI 自定义对话框 引言 jEasyUI是一款流行的前端框架,它提供了一套完整的UI组件,旨在帮助开发者快速构建富客户端应用程序。在jEasyUI中,对话框是一个非常重要的组件,它可以用于显示信息、收集用户输入或执行其他交互任务。本文将详细介绍如何使用jEasyUI自定义对话框…...

MySQL的HAVING:掌握分组过滤的高级用法(实战详解)

本文全面讲解MySQL的HAVING用法&#xff0c;从基础语法到高级技巧&#xff0c;包括分组过滤、聚合查询优化与实战应用。 文章目录一、什么是MySQL的HAVINGHAVING的定义与作用HAVING与WHERE的本质区别二、HAVING的基本语法详解标准语法结构执行顺序解析三、MySQL的HAVING与GROUP…...

M24SR02-Y双接口EEPROM驱动与NFC协议栈解析

1. 项目概述M24SR02-Y 是意法半导体&#xff08;STMicroelectronics&#xff09;推出的双接口&#xff08;IC NFC&#xff09;2-Kbit EEPROM 芯片&#xff0c;集成 ISO/IEC 14443-A Type A 射频接口与标准 IC 通信总线。其核心价值在于实现“有线无线”双模数据交互&#xff1…...

Arduino轻量级CRC-32校验库:零依赖、低内存、确定性执行

1. 项目概述Arduino_CRC32 是一个面向嵌入式场景轻量级 CRC-32 校验库&#xff0c;专为 Arduino 及兼容平台&#xff08;如 STM32 Core for Arduino、ESP32 Arduino Core&#xff09;设计。其核心目标并非追求极致吞吐性能&#xff0c;而是以零依赖、低内存占用、确定性执行时间…...

**发散创新:基于同态加密的隐私保护计算在Python中的实战实现**随

发散创新&#xff1a;基于同态加密的隐私保护计算在Python中的实战实现 随着数据安全需求的不断升级&#xff0c;同态加密&#xff08;Homomorphic Encryption&#xff09; 正从理论走向落地。它允许对加密数据直接进行计算&#xff0c;结果解密后与明文计算一致——这为云计算…...

如何快速部署DeepQA:10分钟搭建你的第一个AI聊天机器人

如何快速部署DeepQA&#xff1a;10分钟搭建你的第一个AI聊天机器人 【免费下载链接】DeepQA My tensorflow implementation of "A neural conversational model", a Deep learning based chatbot 项目地址: https://gitcode.com/gh_mirrors/de/DeepQA DeepQA是…...

制造业上线Agent,能获得哪些核心价值?——2026工业AI从“辅助决策”迈向“全自主执行”的深度解析

站在2026年这个时间节点回望&#xff0c;制造业的数字化转型已完成了从“数据上云”到“智能入链”的惊人跨越。如果说过去十年的工业互联网核心是解决“连接”问题&#xff0c;那么2026年全面爆发的AI Agent&#xff08;智能体&#xff09;则彻底解决了“执行”问题。在当前的…...

“男子靠AI开一人公司年营收达150万”冲上热搜;Claude Code开发团队回应源码泄露:纯属人为失误;树莓派因LPDDR4内存涨价7倍 | 极客头条

「极客头条」—— 技术人员的新闻圈&#xff01;CSDN 的读者朋友们好&#xff0c;「极客头条」来啦&#xff0c;快来看今天都有哪些值得我们技术人关注的重要新闻吧。&#xff08;投稿或寻求报道&#xff1a;zhanghycsdn.net&#xff09;整理 | 郑丽媛出品 | CSDN&#xff08;I…...

返回多个值:让函数输出更丰富又不复杂

一般来说&#xff0c;Python允许函数返回多个值&#xff0c;实质是返回一个元组&#xff08;tuple&#xff09;。调用方可直接通过拆包获得各值&#xff0c;这在数据处理与建模中非常常见。实战案例&#xff1a;假设你要实现一个数据分析函数&#xff0c;既返回最大值&#xff…...

【Python 3.14 JIT性能调优权威指南】:20年CPython核心开发者亲授3大接入瓶颈突破法

第一章&#xff1a;Python 3.14 JIT编译器的演进脉络与接入价值Python 3.14 引入了实验性但高度集成的内置 JIT&#xff08;Just-In-Time&#xff09;编译器&#xff0c;标志着 CPython 运行时首次在官方发行版中提供可生产级启用的动态编译能力。该 JIT 并非独立运行时或第三方…...