本文打包是下载好的tomcat和jenkins的Jenkins.war包。Jenkins.war包安装Jenkins后在安装目录里面
官网下载Tomcat Apache
Jenkins官网下载War包
Jenkins入口地址、登录配置
- 将下载后的
Jenkins
安装,安装之前需要安装JDK
,然后安装Jenkins
,安装之后打开安装后的Jenkins
文件夹,里面存着jenkins.war
包。将该文件挪到Tomcat
里面的webapps
文件夹下。 - 启动
Tomcat 服务
,输入本地IP+端口(可自行设置),默认8080
,或者localhost:8080
打开网页看是否有Tomcat界面,能打开则Tomcat正常启动成功。再该地址后面加上/jenkins
。比如:
http://192.168.2.7:8080/jenkins/
- 打开该地址后可以根据网页提示进行一系列的插件进行默认安装,有一个密码输入,根据该提示打开
secrets
目录下找到存放密码的文件复制粘贴即可。如果打不开,可复制一份修改为.txt格式。
系统管理配置
- 找到系统管理,设置全局配置,首先进行系统设置
ANDROID_HOME
也就是SDK
配置,根据本地环境变量进行设有效路径,再设置全局工具配置,设置JAVA_HOME
也就是JDK
环境变量,所有的都指向本地,而不是从服务端下载,如果自行在自己电脑上测试,则不用勾选,如下图所示:
ANDROID_HOME
D:\androidstudio\sdk
gradle-4.4
C:\Users\cc\.gradle\wrapper\dists\gradle-4.4-all\9br9xq1tocpiv8o6njlyu5op1\gradle-4.4
新建任务,选择自由风格
参数化构建过程
clean
assemble${BuildEnvironment}${BuildFlavors}Release
--stacktrace
--info
E:\jenkins\Test\${BuildSVN}
BuildForPublish
BuildChannel
BuildOutputDir
BuildEnvironment
BuildFlavors
BuildForGrayLevel
构建项目:
Android工程需要注意事项
local.properties配置
gradle.properties配置
主工程Module下的build.gradle配置
-
签名路径
-
签名配置
-
从jenkins服务端接收到消息,传递给
gradle.properties
中的变量对应的值,该值指向build.gradle
文件,打包自行选择
-
同一个手机安装不同包名相同功能的包
-
生成APK
gradle.properties
#jenkins中用到的变量 这个文件用于接收Jenkins配置的变量,名字
#服务器环境接口
BuildEnvironment=Development_xcglcs_wanda_cn
#编辑渠道,开发IDE或者Jenkins
BuildChannel=AndroidStudio
#安装包输出目录
BuildOutputDir=D\://androidstudio/work/WDSGQMSTrunk/wanDa_SGQMS_Trunk/dev/release
#是否要进行发布
BuildForPublish=NO
#是否灰度环境
BuildForGrayLevel=false
build.gradle
//******应用程序ID,务必保证准确性,不得随意更改,最外层目录******
def final mineApplicationId = 'com.cc.sg'
def releaseTime() {
//打包时生成的命名时间
return new Date().format("yyyyMMdd_HHmm")
}
//定义签名文件路径
def getReleaseKeyStoreFile() {
if ("Jenkins".equals(BuildChannel)) {
return file("F:/work/cc/cc.keystore")
} else {
return file("F:/work/cc/cc.keystore")
}
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.cc.sg"
minSdkVersion 14
targetSdkVersion 26
versionCode 11
versionName '1.x'
ndk {
// 设置支持的SO库架构
abiFilters 'armeabi', 'x86'//, 'armeabi-v7a', 'x86_64', 'arm64-v8a','AArch64'
}
}
signingConfigs {
config {
keyAlias 'cc'
keyPassword 'cccccc'
storeFile getReleaseKeyStoreFile()
storePassword 'cccccc'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
}
}
.....省略
//两个维度,一个接口环境,一个发布渠道
flavorDimensions("environment", "pubchannel")
//开发环境域名
def DevelopmentDomain = "域名xc.wd.cn/wd"
//预发布环境域名
def PrepubDomain = "域名10.1x9.2x.5x:x0x0"
//生产环境域名
def ProductionDomain = "域名app.wd.cn"
productFlavors {
Development_域名(方便识别环境) {
dimension 'environment'
buildConfigField "String", "BuildEnvironmentType", "\"Development\""
buildConfigField "String", "BuildEnvironmentSubType", "\"\""
buildConfigField "String", "BuildEnvironmentDomain", "\""+DevelopmentDomain+"\""
buildConfigField "String", "BuildEnvironmentServerURL", "\""+DevelopmentDomain+"/interactedApi/dispatcher"+"\""
buildConfigField "String", "BuildEnvironmentChannel", "\""+BuildChannel+"\""
buildConfigField "String", "BuildForPublish", "\"NO\""
buildConfigField "boolean","BuildForGrayLevel",BuildForGrayLevel//boolean类型
}
Prepub_域名(方便识别环境比如192_168.1.1){
dimension 'environment'
buildConfigField "String", "BuildEnvironmentType", "\"Prepub\""
buildConfigField "String", "BuildEnvironmentSubType", "\"\""
buildConfigField "String", "BuildEnvironmentDomain", "\""+PrepubDomain+"\""
buildConfigField "String", "BuildEnvironmentServerURL", "\""+PrepubDomain+"/interactedApi/dispatcher"+"\""
buildConfigField "String", "BuildEnvironmentChannel", "\""+BuildChannel+"\""
buildConfigField "String", "BuildForPublish", "\"NO\""
buildConfigField "boolean","BuildForGrayLevel",BuildForGrayLevel
}
Production{
dimension 'environment'
buildConfigField "String","BuildEnvironmentType","\"Production\""
buildConfigField "String","BuildEnvironmentSubType","\"\""
buildConfigField "String","BuildEnvironmentDomain","\""+ProductionDomain+"\""
buildConfigField "String","BuildEnvironmentServerURL","\""+ProductionDomain+"/interactedApi/dispatcher"+"\""
buildConfigField "String", "BuildEnvironmentChannel", "\""+BuildChannel+"\""
buildConfigField "String","BuildForPublish","\""+BuildForPublish+"\""
buildConfigField "boolean","BuildForGrayLevel",BuildForGrayLevel
}
//********开发环境(applicationId不一样)******
beta {
dimension 'pubchannel'
applicationId mineApplicationId + ".dev"
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "beta",
app_icon : "@drawable/ic_launcher_test",
app_name : "@string/app_name",
]
}
//********生产环境(默认渠道)******
general {
dimension 'pubchannel'
applicationId mineApplicationId
manifestPlaceholders = [
UMENG_CHANNEL_VALUE: "general",
app_icon : "@drawable/ic_launcher",
app_name : "@string/app_name",
]
}
}
if("Jenkins".equals(BuildChannel)){
android.applicationVariants.all {
variant ->
variant.getPackageApplication().outputDirectory = new File(BuildOutputDir)
variant.outputs.all {
output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
// APK输出文件名规则
def releaseApkName = "cc_${defaultConfig.versionName}_" + variant.flavorName + "_" + variant.buildType.name + "_" + releaseTime() + "_" + "From"+BuildChannel+".apk"
outputFileName = releaseApkName
}
}
}
// }else{
// android.applicationVariants.all {
// variant ->
// variant.outputs.all {
// output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// // 输出apk名称为WDSG__pro/dev_version_time.apk
// def fileName = "cc_${variant.productFlavors[0].name}_V${defaultConfig.versionName}_${releaseTime()}.apk"
// outputFileName = fileName
// }
// }
// }
}
useLibrary 'org.apache.http.legacy'
}
如何导出jenkins配置文件
Basic guide to Import and export jobs in jenkins and Selenium