目標: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命令,可腳本完成複雜需求html
./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
自啓動的腳本是系統啓動的,和登錄用戶不是一個環境java
根據Log 查看什麼錯誤android
目標:1. 構建自動發郵件;2. 郵件模板;3. 組織友好下載連接;
Evaluated Groovy script 添加以下腳本內容,後續的腳本中,能夠引用${CURR_DAY}, ${CURR_TIME}git
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 內容web
文件下載:<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 >