jenkins自动打包apk

来源:互联网 发布:淘宝千人千面怎么用 编辑:程序博客网 时间:2024/06/11 18:53

jenkins自动打包

  1. 首先新建一个构建自由风格的软件项目
  2. General配置项目名称和描述
    • 设定项目名称后会在workspace文件夹下创建以此项目名称命名的文件夹
  3. 源码管理使用Subversion

    • Respository URL设置为svn地址
    • Credentials设置为在Global Setting里添加的账号和密码,也可以直接点击Add来添加
    • Local module directory为svn上的项目下载下来的目录位置,为相对于本Project文件夹的相对位置,此处根据自己的项目设置为xbjy\assets\apps\XBJY\www,即为H5项目down下来的地址
    • Repository depth有四个参数:infinity、empty、files、immediates和as-it-is,分别对应svn的文件update方式。此处使用了as-it-is,需要使用到

      svn update --set-depth=exclude A B C

      方式来过滤不需要更新的文件夹,使用的时候需要先将项目Checkout下来

    • Check-out Strategy默认使用Use’svn update’as much as posibble即可
  4. 构建触发器使用Poll SCM为定时构建,定时跟svn代码比对是否有更新,有更新则立即构建,此处使用(H/15 * * * *),其他参数可网上查询。还有Build periodically方式可以选择,为周期性构建。
  5. 构建环境无选择
  6. 构建时点击增加构建步骤,选择Execute Windows batch command,可以理解为执行DOS环境下的cmd命令,选择Execute shell则是执行linux环境下的shell命令。此处选择batch命令,填入:

    cd xbjyandroid update project -p . -t android-19

    增加构建步骤,选择Ivoke Ant,因为Android项目的构建是由Ant执行的,所以相关的参数需要在此配置,Targets填写clean release,Build File填写../../../../build.xml,此地址为相对于从svn中down下来的文件夹的相对路径,在该相对路径下找到build.xml文件。Properties可以配置Ant编译过程中的参数,例如密钥位置、名称、密码和打包后存放地址。但本项目将参数直接配置在build.xml中,所以此处可以不写

  7. 构建后操作可以选择发送邮件通知,然而本项目没必要,就先不配相关配置。

打包后文件放置

  • 打包后文件为了共享出去,可以在Tomcat里新建一个webapps项目来共享。

    1. 在文件夹webapps里创建一个项目命名为appstore
    2. 在appstore文件夹下创建一个名为WEB-INF的文件夹,里面添加一个web.xml文件,内容为最基础即可

      <?xml version="1.0" encoding="UTF-8"?><!--  Licensed to the Apache Software Foundation (ASF) under one or more  contributor license agreements.  See the NOTICE file distributed with  this work for additional information regarding copyright ownership.  The ASF licenses this file to You under the Apache License, Version 2.0  (the "License"); you may not use this file except in compliance with  the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License.--><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"  version="4.0"  metadata-complete="true">  <display-name>appStore</display-name>  <description>     appStore.  </description></web-app>

      此时名为appstore的项目已经建成,然后在appstore文件夹下放置需要共享的文件即可

Tomcat开机自启

  1. 首先要配置好java环境
  2. 然后新建变量:CATALINA_HOME=你的TOMCAT的目录
  3. 在PATH变量最后加上: ;%CATALINA_HOME%\bin
  4. 运行CMD在DOS窗口下运行service.bat install
  5. 安装完毕以后运行service.msc找到Apache Tomcat的服务修改他的运行级别即可

    注意!! Tomacat使用startup.bat启动和服务方式启动有可能导致两个不一样的Jenkins运行环境,此处需要配置下JENKINS_HOME环境变量为所使用的.jenkins文件夹地址

需要打包项目相关配置

  1. 创建两个文件ant.properties和build.xml,这两个配置文件为打包需要的相关配置。一般ant.properties需要手动创建,build.xml文件项目会自动生成一个默认的。
  2. 以现在的移动项目为例,ant.properties的文件内容如下:

    #项目包名#application.package=com.XXXX.xxxx#项目名称#ant.project.name=MainActivity  #项目编码,这里需要注意自己工程的编码格式,需要保证编码格式一致(可不使用)#java.encoding=utf-8   #编译中间文件生成目录#out.absolute.dir=F:/Test/compile  #指定Bin目录#out.dir=C:/Users/Haven/Desktop/JenkinsTestout.final.file = E:/Program Files (x86)/apache-tomcat-9.0.0.M9/webapps/appstore/abc.apk#签名文件全路径key.store=E:/Program Files (x86)/apache-tomcat-9.0.0.M9/webapps/appstore/XXXXXXXXX.keystore#签名文件密码key.store.password=XXXXXXXXX#别名,这里要注意如果你签名文件的别名为中文,需要和我这个一样转成16进制,不然签名的时候会报错,转码可以用【UltraEdit工具】(自行百度下载)来做。key.alias=XXXXXXXXX#别名密码key.alias.password=XXXXXXXXX#软件版本号#app_version=1.0.0#需要打包的渠道名,注意‘,’分格#market_channels=Gfan,3G,360,AndMarket,AnZi
  3. android项目会自动生成build.xml文件,使用默认的生成的即可

0 0
原创粉丝点击