[original] Jenkins Android Automatic packaging configuration

Source: Internet
Author: User
<span id="Label3"></p>first, Jenkins Automatic Packaging configuration<pre><pre><code class="hljs">目标:1. 自动打包;2. 自动上传;3. 友好下载</code></pre></pre>1. About Jenkins<pre><pre><code class="hljs">Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作。减少重复劳动,减少人工成本。</code></pre></pre> <ul> <ul> <li>Build/test software projects continuously and automatically;</li> <li>Monitor some tasks scheduled for execution;</li> </ul> </ul>2. Jenkins Configuration <ul> <ul> <li>Add git plugin and role plugins</li> <li>Set up people permissions, based on role authorization</li> <li>Start Access http://ip/8080, See below<code>3.1 开机自启脚本</code></li> <li>Add git projects, Configure scripts, see below <code>3.2 项目打包脚本</code> and<code>3.3 Apk上传脚本</code></li> </ul> </ul>3. Automation Script 3.1 power-on Self-start script <ul> <ul> <li>jenkins.sh</li> </ul> </ul><pre><code class="hljs bash"><span class="hljs-meta">#! /bin/sh<span class="hljs-comment"># chkconfig:2345 10 90<span class="hljs-comment"># Description:jenkins ....<span class="hljs-comment"># This script is executed *after* all and the other init Scripts.<span class="hljs-comment"># can put your own initialization stuff in here if you don ' t<span class="hljs-comment"># want to does the full Sys V style init stuff.<span class="hljs-comment">#prefix =/users/laifeng/jenkins<span class="hljs-comment">#nohup $prefix/jenkins_start.sh >> $prefix/jenkins.log 2>&1 &jenkins_root=/users/laifeng/ Jenkinsjenkinsfilename=jenkins.war<span class="hljs-function"><span class="hljs-title">Stop () {<span class="hljs-built_in">Echo<span class="hljs-string">"stoping<span class="hljs-variable">$JENKINSFILENAME "ps-ef|grep<span class="hljs-variable">$JENKINSFILENAME |awk<span class="hljs-string">' {print $} ' |<span class="hljs-keyword">While<span class="hljs-built_in">Read PID<span class="hljs-keyword">Do<span class="hljs-built_in">Kill-9<span class="hljs-variable">$pid<span class="hljs-built_in">Echo<span class="hljs-string"><span class="hljs-string"> "<span class=" hljs-variable "> $pid kill" <span class="hljs-keyword">done}<span class=" Hljs-keyword ">case <span class=" hljs-string ">" <span class="hljs-variable">$1 "<span class=" Hljs-keyword ">instart ) <span class="hljs-built_in">echo <span class="hljs-string"> "starting <span class=" hljs-variable ">$ Jenkinsfilename "nohup java-jar <span class=" hljs-variable "> $JENKINS _root/jenkins.war--httpport=8080 >> <span class="hljs-variable"> $JENKINS _root/jenkins.log 2>&1 &; STOP) stop;; Restart) Stop start;; Status) ps-ef|grep <span class="hljs-variable"> $JENKINSFILENAME;; *) <span class="hljs-built_in">printf <span class="hljs-string"> ' Usage:%s {start|stop|restart|status}\n ' <span class="hljs-string"> "<span class=" hljs-variable "> $prog" <span class="hljs-built_in">exit 1;; <span class="hljs-keyword">esac </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre> <ul> <ul> <li>jenkins_start.sh</li> </ul> </ul><pre><pre><code class="hljs bash"><span class="hljs-meta">#!/bin/bash<span class="hljs-built_in">export ANDROID_HOME=/usr/<span class="hljs-built_in">local/android-sdk<span class="hljs-built_in">export GRADLE_HOME=/usr/<span class="hljs-built_in">local/gradle-2.2.1<span class="hljs-built_in">export JENKINS_HOME=/Users/laifeng/.jenkins/Users/laifeng/jenkins/jenkins.sh start/usr/<span class="hljs-built_in">local/apache-tomcat-7.0.67/bin/startup.sh</span></span></span></span></span></span></span></code></pre></pre> <ul> <ul> <li>Start on Mac</li> </ul> </ul><pre><pre><code class="hljs nginx"><span class="hljs-attribute">sudo defaults write com.apple.loginwindow LoginHook /path/to/script 设置/path/to/script = /Users/laifeng/jenkins/jenkins_start.sh</span></code></pre></pre>3.2 Automated packaging and uploading of project packaging scripts<p><p>Currently running the Gradle command directly, can be scripted to complete complex requirements</p></p><pre><pre><code class="hljs">./gradlew clean assembleDebug</code></pre></pre>apk upload Script <ul> <ul> <li>deploy.sh</li> </ul> </ul><pre><code class="hljs bash"><span class="hljs-meta">#!/bin/sh<span class="hljs-built_in">Echo<span class="hljs-string">"deploy begin ..." Apkname=<span class="hljs-variable">$1currday=$ (date +%y-%m-%d) currtime=$ (date +%h-%m-%s) deploypath=<span class="hljs-string">"/users/laifeng/jenkins/android-apks/<span class="hljs-variable">${currday} "<span class="hljs-comment">#echo "$deployPath"<span class="hljs-comment"># Create a folder<span class="hljs-keyword">If [!<span class="hljs-_"><span class="hljs-_">-d <span class="hljs-string"> "<span class=" hljs-variable "> $deployPath"]; <span class=" Hljs-keyword ">then mkdir <span class=" hljs-string ">" <span class="hljs-variable"> $deployPath " <span class="hljs-keyword">fi<span class="hljs-comment"># copy files to directory Workspaceapkfile=<span class="hljs-variable" " span>${workspace}/crazytogether/build/outputs/apk/crazytogether-debug.apk "deployApkFile=< Span class= "hljs-string" > "<span class=" hljs-variable ">${deploypath}/<span class=" hljs-variable ">${apkName}-< Span class= "hljs-variable" >${currtime}.apk "<span class=" hljs-comment "> #echo" $workspaceApkFile "<span class=" Hljs-comment "> #echo" deployapkfile "cp <span class=" hljs-variable ">${workspaceapkfile} <span class="hljs-variable">${deployapkfile}<span class="hljs-built_in">echo <span class="hljs-string"> "deploy Success ... "</span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>Tomcat File Server<pre><code class="hljs xml">1. Create an arbitrary file name XML file under the Tomcat installation directory \conf\catalina\localhost, for Example: download.xml<span class="hljs-meta"><?xml version= "1.0" encoding= "UTF-8"?><span class="hljs-tag"><<span class="hljs-name">Context<span class="hljs-attr">Path=<span class="hljs-string">"/download"<span class="hljs-attr">Docbase=<span class="hljs-string">"d://download"<span class="hljs-attr">crosscontext=<span class="hljs-string">"true" ><span class="hljs-tag"></<span class="hljs-name">Context> 2. Modify the Tomcat configuration file, file directory \conf\web.xml, to change the red false to True<span class="hljs-tag"><<span class="hljs-name">Servlet><span class="hljs-tag"><<span class="hljs-name">Servlet-name>default<span class="hljs-tag"></<span class="hljs-name">Servlet-name><span class="hljs-tag"><<span class="hljs-name">Servlet-class>org.apache.catalina.servlets.defaultservlet<span class="hljs-tag"></<span class="hljs-name">Servlet-class><span class="hljs-tag"><<span class="hljs-name">Init-param><span class="hljs-tag"><<span class="hljs-name">Param-name>debug<span class="hljs-tag"></<span class="hljs-name">Param-name><span class="hljs-tag"><<span class="hljs-name"><span class="hljs-name">param-value>0<span class="hljs-tag"></<span class="hljs-name">param-value> Span class= "hljs-tag" ></<span class="hljs-name">init-param> <span class="hljs-tag">< <span class="hljs-name">init-param> <span class="hljs-tag"><<span class="hljs-name">param-name> Listings<span class="hljs-tag"></<span class="hljs-name">param-name> <span class="hljs-tag"><<span class="hljs-name">param-value>false<span class="hljs-tag"></<span class="hljs-name">param-value> <span class="hljs-tag"></<span class="hljs-name">init-param> <span class="hljs-tag">< <span class="hljs-name">load-on-startup>1<span class="hljs-tag"></<span class="hljs-name"> load-on-startup> <span class="hljs-tag"></<span class="hljs-name">servlet> 3. Reboot tomcat to access http:// 127.0.0.1:8080/download </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>Problems encountered <ul> <ul> <li>Add Git project cannot get permissions, create ssh key, upload local SSH key public key to your user's git server, add authentication in jenkins, SSH private key.</li> <li>Self-startup scripts fail to execute smoothly, missing environment variables, inconsistent user initiation, boot sequence, add necessary environment variables in startup script</li> <li><p>The self-initiated script is system-initiated, and the logged-on user is not an environment</p></li> <li>First run locally to ensure the correctness of the script</li> <li><p>See what error according to log</p></li> </ul> </ul>second, Jenkins Mail Configuration<pre><pre><code class="hljs">目标:1. 构建自动发邮件;2. 邮件模板;3. 组织友好下载链接;</code></pre></pre>1. Mail Configuration <ol> <li><li>Add plugin: Email Extension Plugin</li></li> <li><li>Set the SMTP server: system management, system settings, set the SMTP service in the Extended e-mail notification entry. Note the setting is not a Jenkins mail notification entry.</li></li> <li><li>To set the job mail configuration: <ul> <li>In the "add post build steps" select "Editable Email Notification"</li> <li>Project Recipient List, set up accept mailboxes, separate multiple mailbox spaces</li> <li>Content Type, Select as HTML</li> <li>Default Subject, message Header</li> <li>Default content, message content, HTML can be written</li> <li>Note: "global Mail variables" can be used in these options, see links</li> </ul></li></li> <li><li> How to set up a friendly download link: <ul> <li> changes every time, primarily "time variables" </li> <li> "time variables", day,time needs to be set to Jenkins's environment variables so that subsequent executions can share these variables, using </li> <li> "build environment": tick "Inject environment variables to the build process", set Groovy script in the "evaluated Groovy script" option below, Add to environment variable </li> <l i> Modify the "build excute shell" deploy.sh script, The time variable in the script is not defined locally, but instead uses the build variable set above ${curr_day}, ${curr_time} <li> to modify the Editable Email Notification "," Default Content ", Current version based on" time variable "${curr_day}, ${curr_time} dynamic production </li> </l> </ul> </li></li> <li><li><p>The evaluated Groovy script adds the following script content, which can be referenced in subsequent scripts ${curr_day}, ${curr_time}</p><pre><code class="hljs ruby">TimeZone.setDefault(TimeZone.getTimeZone(<span class="hljs-string">‘Asia/Shanghai‘))<span class="hljs-function"><span class="hljs-keyword">def <span class="hljs-title">now = <span class="hljs-title">new <span class="hljs-title">Date<span class="hljs-params">()<span class="hljs-function"><span class="hljs-keyword">def <span class="hljs-title">map = [<span class="hljs-title">CURR_DAY: <span class="hljs-title">now.<span class="hljs-title">format<span class="hljs-params">(<span class="hljs-string">‘yyyy-MM-dd‘), <span class="hljs-symbol">CURR_TIME: now.format(<span class="hljs-string">‘HH-mm-ss‘)]<span class="hljs-keyword">return map</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre></li></li> <li><li><p>Email Default Content Contents</p></li></li> </ol><pre><code class="hljs xml">File download:<span class="hljs-tag"><<span class="hljs-name">Br/><span class="hljs-tag"><<span class="hljs-name">Hr/> Current Version:<span class="hljs-tag"><<span class="hljs-name">A<span class="hljs-attr">href=<span class="hljs-string">"http://10.155.59.205:8081/download/${curr_day}/branch-2.6.1-${curr_time}.apk"<span class="hljs-attr">target=<span class="hljs-string">"_blank" > Click to download<span class="hljs-tag"></<span class="hljs-name">A><span class="hljs-tag"><<span class="hljs-name">Br/> Historical Version:<span class="hljs-tag"><<span class="hljs-name">A<span class="hljs-attr">href=<span class="hljs-string">"http://10.155.59.205:8081/download"<span class="hljs-attr">target=<span class="hljs-string">"_blank" >http://10.155.59.205:8081/download<span class="hljs-tag"></<span class="hljs-name">A><span class="hljs-tag"><<span class="hljs-name">Br/><span class="hljs-tag"><<span class="hljs-name">Br/> Build Information:<span class="hljs-tag"><<span class="hljs-name">Br/><span class="hljs-tag"><<span class="hljs-name">Hr/> Project Name: $PROJECT _name<span class="hljs-tag"><<span class="hljs-name">br/> Build Number: $BUILD _number<span class="hljs-tag"><<span class="hljs-name">br/> Build Status: $BUILD _status<span class="hljs-tag"><<span class="hljs-name">Br/> Trigger Reason: ${cause}<span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-name">br/> build log address: <span class="hljs-tag">< <span class="hljs-name">a <span class="hljs-attr">href=<span class="hljs-string"> "${build_url}console" >${ Build_url}console<span class="hljs-tag"></<span class="hljs-name">a><span class="hljs-tag"><<span class="hljs-name">br/> Build address: <span class="hljs-tag"><<span class="hljs-name">a <span class="hljs-attr">href =<span class="hljs-string"> "$BUILD _url" > $BUILD _url<span class="hljs-tag"></<span class="hljs-name">a> <span class="hljs-tag"><<span class="hljs-name">br/> changeset: ${jelly_script,template= "html"} <span class="hljs-tag"><<span class="hljs-name">br/><span class="hljs-tag"><<span class="hljs-name"> hr/> (this Email is automatically issued by the program, do not reply!) <span class="hljs-tag"><<span class="hljs-name">br; </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>2. Other ISSUES <ul> <ul> <li>The SMTP mail service does not work as expected because of issues such as SSL licensing, SMTP ports, and so on</li> <li>Time zone problem is 8 hours less by default and requires TimeZone to "asia/shanghai"</li> <li></li> </ul> </ul><p><p>Http://www.cnblogs.com/purediy/p/5160813.html</p></p><p><p></p></p><p><p>[original] Jenkins Android Automatic packaging configuration (go)</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.