本文多是网上最全的一篇全端jenkins部署解决方案介绍的文章,一直以来,领导都想解决代码提交和打包问题,尤为是小公司,打包流程混乱,形成线上版本和代码库git或svn中代码不一致问题。加入jenkins阵营,解决众多发包难题,显得刻不容缓。java
刚开始,我一直在docker下安装jenkins,按时长租用阿里的主机,用阿里容器服务作实验,反复建立docker容器,创建多个jenkins节点。结果发现,在容器中配置各类变量比较复杂,各类开发环境不易快速部署,固然啦,是刚开始的对jenkins研究过少形成的。后来我采用了windows主机,配java、maven、Android环境,踩了一路坑,终于搞定了。可是我知道ios开发和编译必须使用mac系统,原本想增长一个jenkins节点来实现ios的编译。当配置好以后,我忽然改变了主意,与其两台电脑开着,不如索性把整个jenkins部署到mac系统下(毕竟咱们公司暂时没有c#工程)。因而,全部的操做,全部的环境我又折腾了一遍。下面我逐一讲解最终mac下实现全端jenkins持续集成,固然不包含c#,一路踩坑下来,我以为这都不是事,流程都差很少。android
我我的比较喜欢新事物,因此建议使用较高版本,我使用的2.61,目前最新版是2.75。
mac下使用brew安装,终端执行ios
brew install jenkins复制代码
等安装完成后,终端运行jenkins便可启动。git
jenkins复制代码
这个比较简单,直接从appstore下载最新版便可。
安装后,将公司项目拉入xcode,先保证项目在本机编译,这里我登陆了app开发者账号,以便下载各类证书及发布。github
这个到这里下载www.android-studio.org/docker
由于咱们公司用的是git,若是贵公司使用svn,则同理,只需保git或者svn命令能够敲出来便可。
我这里的版本比较老,尽可能使用新的,我懒得换了。c#
mac:~ shaolei$ git version
git version 2.11.0复制代码
这是一个很是好用的git可视化工具,改天会具体介绍它的强大功能。
这款软件不是必须的,只是为了方便项目拉取,因此,你能够跳过此步骤。windows
这里才是相当重要的一项,本文的核心xcode
Starts an Android emulator with given properties before a build, then shuts it down after.复制代码
This plugin allows builds to be automatically terminated after the specified amount of time has elapsed.复制代码
This plugin is a replacement for Jenkins's email publisher 复制代码
This plugin allows Jenkins to invoke Gradle build scripts directly.复制代码
This plugin integrates management of keychain and provisioning files for iOS and OSX projects.复制代码
This plug-in provides, for better and for worse, a deep integration of Jenkins and Maven: Automatic triggers between projects depending on SNAPSHOTs, automated configuration of various Jenkins publishers (Junit, ...). 复制代码
A suite of plugins that lets you orchestrate automation, simple or complex. See Pipeline as Code with Jenkins for more details. 复制代码
Allows Pipeline Grrovy libraries to be loaded on the fly from GitHub.复制代码
Allows to launch agents over SSH, using a Java implementation of the SSH protocol.复制代码
Subversion Plug-inandroid-studio
Timestamper
Adds timestamps to the Console Output复制代码
This plugin deletes the project workspace after a build is finished.复制代码
This plugin provides builders to build xcode projects, invoke agvtool and package .ipa files复制代码
其中Android Emulator Plugin、Gradle Plugin是安卓必须插件;其中Keychains and Provisioning Profiles Management、Pipeline、Xcode integration是ios编译必须插件;其中Maven Integration plugin、SSH Slaves plugin是maven项目必须插件,其余的Email Extension Plugin这个是为了编译失败的时候通知具体提交代码开发人员邮件
建立安卓job
和安卓相同的源代码管理及触发器不作介绍,请参照安卓,下文同理。
cd ${WORKSPACE}
mvn clean
cd ${WORKSPACE}/******/src/main/resources/
echo ${BUILD_NUMBER} >ver.xml复制代码
固然了,这里用到了几个关键词变量,是jenkins特有的,更多变量参照下文:
CHANGE_AUTHOR
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.
CHANGE_AUTHOR_DISPLAY_NAME
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.
CHANGE_AUTHOR_EMAIL
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.
CHANGE_TARGET
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.
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
…………………………………………等等复制代码
这里我就用了zip打包,部署时使用zip解压到指定目录便可。
cd ${WORKSPACE}
echo ${BUILD_NUMBER} >ver.txt
zip -r h5.zip ./ -x .git\* -x README.md -x .project -x .gitignore
cp ${WORKSPACE}/h5.zip /Volumes/***/H5/h5-${BUILD_NUMBER}.zip复制代码
本文全面讲解了jenkins各项目持续继承方案,由于涉及环境过多,坑仍是比较多的,但愿自行填坑。