android 使用jenkins打包 mac 配置记录

说明:本文仅用于个人记录

安装步骤

安装步骤就不说了,这里直接说项目配置,安装步骤参见:https://www.jianshu.com/p/74dd11121fc7

创建项目

  • 点击新建item


    image.png
  • 输入项目名称--选择第一个freestyle projetc--点击确定


    image.png

配置项目

  • 进入自己的项目,点击配置


    image.png

常规配置

  • 描述


    image.png
  • 配置一些扩展参数(给到脚本使用)


    image.png

    这里配置的是一些简单的String 参数(主要用于上传apk包,以及发通知给到企业微信)

源码配置

image.png

构建触发器配置

image.png

这里可以选按时轮训(如图),也可以选择其他方式,比如自动监控git提交并触发(这里有个小坑,好像本地ip直连的gitlab不支持,需要有域名的才行)
更多设置细节参见:https://www.jianshu.com/p/ff31b08dadfe

构建

image.png

这里的gradle直接在jenkins就可以安装了


image.png

最后我们还可以添加一些excute shell 脚本

MSG=${SCM_CHANGELOG}
echo MSG
DISPATCH_APP_KEY="xxxxxx"
IPA_FILE_PATH="/Users/jenkins/.jenkins/workspace/xxx_android/app/build/outputs/apk/daily/release/app-daily-release.apk"
DATE="$(date "+%Y%m%d_%H:%M:%S")"
IPA_UPLOAD_RESPONSE=$(curl -F "file=@${IPA_FILE_PATH}" https://static.xxx.com/upload?scenes=package&output_type=json)
IPA_URL=$(python /Users/jenkins/Desktop/analysis-upload-response.py ${IPA_UPLOAD_RESPONSE})

echo ${IPA_URL}

DISPATCH_REQUEST_URL="https://dispatch.oa.xxx.com/xxx/xxx/xx.json?fappKey=${DISPATCH_APP_KEY}&fappVersion=${DATE}&fappUrl=${IPA_URL}&fsize=40&fversionDesc=Demo"
curl ${DISPATCH_REQUEST_URL}
curl -d "touser=${xxxPushUser}" -d 'agent_id=1000011' -d 'is_textcard_flag=1' -d "description=${xxxDescription}${MSG}" -d "title=${xxxPushTitle}" -d "url=${xxxHref}" http://xxx/weixin/send/msg.json

这里需要注意一些路径,在ios和win可能不太一样,为了省心可以直接配置全路径。

坑点

项目太大,git拉取失败

Receiving objects:  93% (4502/4814), 1012.85 MiB | 3.67 MiB/s   
Receiving objects:  93% (4504/4814), 1015.59 MiB | 3.84 MiB/s   
Receiving objects:  93% (4505/4814), 1021.38 MiB | 3.84 MiB/s   
Receiving objects:  93% (4506/4814), 1.00 GiB | 3.89 MiB/s   
Receiving objects:  93% (4508/4814), 1.00 GiB | 3.94 MiB/s   
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:72)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:442)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:886)
    ... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

参考链接:https://www.jianshu.com/p/c8e7ab672a67
解决方案:设置超时时间,使用浅克隆
浅克隆功能,只clone少部分历史到本地,这样可以极大的减少clone的仓库大小

image.png

项目报内存溢出

> **Task :app:mergeDailyReleaseNativeLibs**

Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted

> **Task :app:compileDailyReleaseJavaWithJavac** FAILED

系统资源不足。
有关详细信息, 请参阅以下堆栈跟踪。
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.util.EnumSet.noneOf(EnumSet.java:115)
    at com.sun.tools.javac.util.JCDiagnostic$Factory.create(JCDiagnostic.java:223)
    at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.reportMC(Resolve.java:779)
    at com.sun.tools.javac.comp.Resolve$4$2.report(Resolve.java:882)
    at com.sun.tools.javac.comp.Check.checkType(Check.java:553)
    at com.sun.tools.javac.comp.Attr$ResultInfo.check(Attr.java:482)
    at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1015)
    at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:835)
    at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:735)
    at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:844)
    at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:579)
    at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1446)
    at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1633)
    at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1704)
    at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1677)
    at com.sun.tools.javac.comp.Resolve$14.doLookup(Resolve.java:2689)
    at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3097)
    at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3348)
    at com.sun.tools.javac.comp.Resolve.resolveOperator(Resolve.java:2685)
    at com.sun.tools.javac.comp.Resolve.resolveBinaryOperator(Resolve.java:2726)
    at com.sun.tools.javac.comp.Attr.visitBinary(Attr.java:3061)
    at com.sun.tools.javac.tree.JCTree$JCBinary.accept(JCTree.java:1785)
    at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
    at com.sun.tools.javac.comp.Attr.visitParens(Attr.java:2986)
    at com.sun.tools.javac.tree.JCTree$JCParens.accept(JCTree.java:1661)
    at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
    at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:618)
    at com.sun.tools.javac.comp.Attr.visitIf(Attr.java:1581)
    at com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1269)
    at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
    at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
    at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDailyReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

修复方案:按照箭头指示配置即可


image.png

image.png
键:GRADLE_OPTS
值:-Dorg.gradle.jvmargs=-Xms1024M -Xmx8192M -XX:PermSize=512M -XX:MaxPermSize=2048 -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
键:JAVA_OPTS
值:-XX:MaxPermSize=2048M

-jvmargs 代表后面是设置jvm的参数
-Xms 128M JVM设置最小分配的堆内存
-Xmx 512M JVM允许最大分配的堆内存,按需分配
-XX:PermSize=64M JVM设置分配最小的非堆内存
-XX:MaxPermSize=128M JVM最大允许分配的非堆内存,按需分配
参考地址:https://stackoverflow.com/questions/14762162/how-do-i-give-jenkins-more-heap-space-when-its-running-as-a-daemon-on-ubuntu

mac 脚本无访问权限

可以把脚本直接放到当前用户目录即可

你可能感兴趣的:(android 使用jenkins打包 mac 配置记录)