标签:
目标:1. 自动打包;2. 自动上传;3. 友好下载
Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作。
减少重复劳动,减少人工成本。
3.1 开机自启脚本
3.2 项目打包脚本
和3.3 Apk上传脚本
#! /bin/sh
# chkconfig: 2345 10 90
# description: jenkins ....
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.
#prefix=/Users/laifeng/jenkins
#nohup $prefix/jenkins_start.sh >> $prefix/jenkins.log 2>&1 &
JENKINS_ROOT=/Users/laifeng/jenkins
JENKINSFILENAME=jenkins.war
stop(){
echo "Stoping $JENKINSFILENAME "
ps -ef|grep $JENKINSFILENAME |awk ‘{print $2}‘|while read pid
do
kill -9 $pid
echo " $pid kill"
done
}
case "$1" in
start)
echo "Starting $JENKINSFILENAME "
nohup java -jar $JENKINS_ROOT/jenkins.war --httpPort=8080 >> $JENKINS_ROOT/jenkins.log 2>&1 &
;;
stop)
stop
;;
restart)
stop
start
;;
status)
ps -ef|grep $JENKINSFILENAME
;;
*)
printf ‘Usage: %s {start|stop|restart|status}\n‘ "$prog"
exit 1
;;
esac
#!/bin/bash
export ANDROID_HOME=/usr/local/android-sdk
export GRADLE_HOME=/usr/local/gradle-2.2.1
export JENKINS_HOME=/Users/laifeng/.jenkins
/Users/laifeng/jenkins/jenkins.sh start
/usr/local/apache-tomcat-7.0.67/bin/startup.sh
sudo defaults write com.apple.loginwindow LoginHook /path/to/script
设置/path/to/script = /Users/laifeng/jenkins/jenkins_start.sh
目前是直接运行Gradle命令,可脚本完成复杂需求
./gradlew clean assembleDebug
#!/bin/sh
echo "deploy begin......"
apkName=$1
currDay=$(date +%Y-%m-%d)
currTime=$(date +%H-%M-%S)
deployPath="/Users/laifeng/jenkins/android-apks/${currDay}"
#echo "$deployPath"
# 创建文件夹
if [ ! -d "$deployPath" ]; then
mkdir "$deployPath"
fi
# 拷贝文件到目录
workspaceApkFile="${WORKSPACE}/crazytogether/build/outputs/apk/crazytogether-debug.apk"
deployApkFile="${deployPath}/${apkName}-${currTime}.apk"
#echo "$workspaceApkFile"
#echo "deployApkFile"
cp ${workspaceApkFile} ${deployApkFile}
echo "deploy success......"
1. 在tomcat安装目录\conf\Catalina\localhost下建立任意文件名xml文件,比如:download.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/download" docBase="D://download" crossContext="true">
</Context>
2. 修改tomcat配置文件,文件目录\conf\web.xml,要将红色的false改为true
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
3. 重启tomcat,访问http://127.0.0.1:8080/download
自启动的脚本是系统启动的,和登陆用户不是一个环境
根据Log 查看什么错误
目标:1. 构建自动发邮件;2. 邮件模板;3. 组织友好下载链接;
Evaluated Groovy script 添加如下脚本内容,后续的脚本中,可以引用${CURR_DAY}, ${CURR_TIME}
TimeZone.setDefault(TimeZone.getTimeZone(‘Asia/Shanghai‘))
def now = new Date()
def map = [CURR_DAY: now.format(‘yyyy-MM-dd‘), CURR_TIME: now.format(‘HH-mm-ss‘)]
return map
Email Default Content 内容
文件下载:<br/><hr/>
当前版本:<a href="http://10.155.59.205:8081/download/${CURR_DAY}/branch-2.6.1-${CURR_TIME}.apk" target="_blank">点击下载</a><br/>
历史版本:<a href="http://10.155.59.205:8081/download" target="_blank">http://10.155.59.205:8081/download</a><br/><br/>
构建信息:<br/><hr/>
项目名称:$PROJECT_NAME<br/>
构建编号:$BUILD_NUMBER<br/>
构建状态:$BUILD_STATUS<br/>
触发原因:${CAUSE}<br/>
构建日志地址:<a href="${BUILD_URL}console">${BUILD_URL}console</a><br/>
构建地址:<a href="$BUILD_URL">$BUILD_URL</a><br/>
变更集:${JELLY_SCRIPT,template="html"}<br/><hr/>
(本邮件是程序自动下发的,请勿回复!<br >
http://www.cnblogs.com/purediy/p/5160813.html
标签:
原文地址:http://www.cnblogs.com/softidea/p/5161444.html