本文主要讲述如何利用 Jenkens构建工具打出Android apk 包, 步骤如下:
- 进入到jenkens页面,点击左上角的"新建任务", 输入构建的任务名称,选择"构建一个自由风格的软件项目"

- General 选项勾选"参数化构架过程", 点击添加参数,弹窗参数选择框

, 在选择框中可以选择 Git Parameter 、选项参数等,以下主要介绍 Git Parameter 和选项参数
Git Parameter
Git Parameter 是跟 git相关的,例如配置需要构建的分支时,就可以选择这个

- name: 填写参数名称,可以自由定义
- Description:参数描述(在打包页面会显示在参数设置的下面)
- Parameter Type:可选择 Tag,Branch, Branch or Tag ,Reision,Pull Request
如果要选择默认为某个分支,可以点击右下角的"高级",弹出更多的设置选项

其中
- Branch Filter: 设置需要展示的分支名称的正则表达式,只有满足正则表达式的分支才会展示
- Sort Mode:分支排序
- Default Value:默认选中的分支名称
- Select Value: Default 代表不做任何选中处理, Top 默认显示在第一个并选中 * Default 显示在其本身的位置并选中
选项参数
当要配置打包环境为 测试环境还是生产环境时,可以配置如下

当要配置打包渠道时,可以配置如下

源码管理

选择源码管理平台,我们这里选择 "Git"
- Repositories:输入 源码地址
- Credentials: 选择证书
- Branches to build : 选择 要构建的分支, 这里 ${build_branch} 的名字需要和上面添加"git parameter"中定义的参数名称一致
构建

这里选择构建的gradle版本
和执行的task
app:clean
app:assemble${product_account}${product_channel}${build_type}
增加构建后操作步骤

用于存档的文件:
在 用于存档的文件中通过 正则表达式 可以指定文件的路径。 设置完毕后,每次构建完成后 Jenkins会在 Console Output中采用设定的正则表达式进行搜索匹配,如果成功匹配到文件则会将文件收集起来。
例如 " */.apk " 代表只将 ".apk" 后缀的文件归档
至此所有的配置就完成了,接下来回到 Jenkens构建页面,点击 "Build with Paramertes" 开始构建, 构建完成

点击"构建产生文件" 就可以获取包了
网友评论