举两个例子:
12
3
4 // every minute
* * * * *
// every 5 mins past the hour
5 * * * *
配置gradle - android专用
请ios的朋友们请飘过.
如果安装gradle插件成功的话,应该会出现下图的Invoke Gradle script,配置一下:
${WORKSPACE}表示当前job下的workspace目录,主要是存放代码。更多的环境变量请参考文末附录。
这样,就能自动在project下的app的build/outputs/apk下生成相应的apk.
编译失败?可能要解决以下2个问题:
gradle没配置环境变量。
比如我在/etc/profile中配置一下GRADLE_HOME:
2 export GRADLE_HOME='/home/jay/.gradle/wrapper/dists/gradle-2.2.1-all/c64ydeuardnfqctvr1gm30w53/gradle-2.2.1'
export PATH=$GRADLE_HOME/bin:$PATH
找不到local.properties中sdk定义。
因为一般来说local.properties不会添加到版本库。
所以需要手动copy到${WORKSPACE}下的Project目录下(可参考自己Android Studio工程结构)。
关于local.properties的定义,这里记录一下,做个备份:
再编译一般就会编译成功,当然当那些第三方库需要重新下载的话,编译可能会很慢。
配置xcode - ios专用请android的同学们飘过。
安装Xcode插件后,可看到如下图界面,并配置:
这里有两个地方需要注意。
签名
需要Shared Schema文件.
上传到蒲公英平台在官网文档里有说明,通过linux平台上传app的关键代码
1 curl -F "file=@/tmp/example.ipa" -F "uKey=" -F "_api_key="具体来说,
12 # 先把${version}看成v1.0吧
curl -F "file=@/home/xxx/release/ganchai-release-${version}-0101-dev.apk" -F "uKey=231xxxxe6" -F "_api_key=0xxxx499" -F "publishRange=2"
这样就完成一个app上传到蒲公英了。
实际上,我们可能会面对更复杂的场景,比如上面的${version}, 而version定义于build.gradle如下:
12
3
4
5
6
7
8 ext {
compileSdkVersion = 22
buildToolsVersion = "23.0.1"
minSdkVersion = 10
targetSdkVersion = 22
versionCode = 1111
versionName = "v1.2.0.0"
}
得想办法读到versionName, 然后拼出最终的文件名,这样下次版本升级了之后也能动态的上传app到蒲公英了。
12 # 使用sed命令读取,使用cut切割,最终动态读取到versionName
version=`sed -n '21,1p' ${WORKSPACE}/xxx/build.gradle | cut -c20-27`
这是android的apk上传过程,相应的,ios是上传ipa,方法是一样的,不再赘述。
小结把开发人员发布版本的工作自动化之后,如此一来,方便了测试人员随时拉取并构建最新版本,更解放了开发人员自己的发版本的工作,一个字,善!
附录jenkins中定义的那些环境变量:
The following variables are available to shell scripts BUILD_NUMBER The current build number, such as "153" BUILD_ID The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss) 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 :port/jenkins/ (note: only available if Jenkins URL set in system configuration) BUILD_URL Full URL of this build, like :port/jenkins/job/foo/15/ (Jenkins URL must be set) JOB_URL Full URL of this job, like :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.