【Android】使用Jenkins+Gradle+FTP,实现自动打包,自动上传文件至FTP

4 篇文章 0 订阅
1 篇文章 0 订阅

一、Jenkins Gradle自动打包

1、安装gradle插件

系统管理–>插件管理

2、创建Job

构建一个自由风格的软件项目,如下图:
这里写图片描述

3、指定项目名称,描述,Shared Workspace

Shared Workspace:
是否使用共享目录,建议设置为NONE,不使用共享目录即私有工作空间。
这里写图片描述

4、指定运行时的一些变量,此处使用jenkins的默认配置,指定ANDROID_HOME

这里写图片描述

5、Restrict where this project can be run

指定运行节点,具体节点需要在 【系统管理–>节点管理】 配置中。

6、源码管理

指定源码位置,并且配置访问账户,指定检出策略。如下图:
Check-out Strategy
检出策略,update之前使用revert还原本地更改。
这里写图片描述

7、构建,指定命令和任务

由于在打包所以仅设定了打包release版本,即assembleRelease。如下图:
记得需要勾选【Make gradlew executable】,否则会有权限问题。使用Gradle Wrapper,方便打包。
这里写图片描述

8、构建后操作

打包目标文件
这里写图片描述

二、安装FTP服务器,并将打包结果push到指定目录

1、安装ftp插件

系统管理–>插件管理
这里我用的是 Publish Over FTP

2、配置ftp服务器

在【系统管理–>系统设置】配置ftp服务器信息,填写 服务名,host,用户名,密码。如下图:
注意,测试连接性时,不要依据当前电脑或者jenkins服务器,因为在做ftp上传时,具体的运行位置取决于你在job中配置的节点信息,所以是否能连通是以节点能否连通ftpserver为准。
这里写图片描述

3、在Job中配置构建后操作,即发布到ftp服务器

将打包文件发送到指定的FTP服务器,注意以下字段的配置。最终如下图:

        Remove prefix
            忽略前置目录,即上传至ftp服务器时,不去创建的目录
            如:
                app\build\outputs\apk
                app打包时的目录结构
        Remote directory
            ftp服务器目录的命名规则,使用Jenkins自带的环境变量,使用方法有${JOB_NAME}$JOB_NAME
            如:
                ${JOB_NAME}\${BUILD_NUMBER}_${SVN_REVISION}
                构建任务名称\构建编号_svn版本号

这里写图片描述

4、Jenkins内置的环境变量

The following variables are available to shell scripts

BUILD_NUMBER
   The current build number, such as "153"
BUILD_ID
   The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds
BUILD_DISPLAY_NAME
   The display name of the current build, which is something like "#153" by default.
JOB_NAME
   Name of the project of this build, such as "foo" or "foo/bar". (To strip off folder paths from a Bourne shell script, try: ${JOB_NAME##*/})
BUILD_TAG
   String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". Convenient to put into a resource file, a jar file, etc for easier identification.
EXECUTOR_NUMBER
   The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
NODE_NAME
   Name of the slave if the build is on a slave, or "master" if run on master
NODE_LABELS
   Whitespace-separated list of labels that the node is assigned.
WORKSPACE
   The absolute path of the directory assigned to the build as a workspace.
JENKINS_HOME
   The absolute path of the directory assigned on the master node for Jenkins to store data.
JENKINS_URL
   Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)
BUILD_URL
   Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)
JOB_URL
   Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)
SVN_REVISION
   Subversion revision number that's currently checked out to the workspace, such as "12345"
SVN_URL
   Subversion URL that's currently checked out to the workspace.
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值