• Jenkins自动化构建vue项目然后发布到远程Linux服务器


    部署Jenkins参照另一篇博客:

    centos7安装Jenkins及其卸载

    一、jenkins相关插件的安装

    1、安装Publish Over SSH插件用于SSH连接远程的服务器。     

    登录 jenkins 管理系统首页,打开“系统管理”--“管理插件”  搜索 Publish Over SSH 然后勾选安装

    2、安装 NodeJs插件 用于vue项目打包构建。 

    打开“系统管理”--“管理插件”  搜索 nodejs 然后勾选安装

    打开“系统管理”--“Global Tool Configuration”   拉到底部 配置  node 版本,如图:

    二、配置远程服务器的连接

    1、打开“系统管理”--“系统设置”  找到 “Publish over SSH” 项 ,如果是帐号密码登录的Passphrase填写密码Username填写用户名,path to key 为空就可以了。也可以通过远程服务器用的是ssh登录,通过ppk密钥进行连接。点击 Test Configuration 按钮测试连接是否成功

    三、配置自动部署任务

    1、新建任务:点击“新建”--填写任务名称,选择“构建一个自由风格的软件项目”然后保存,如图:

    2、配置git,进入任务配置,选择源码管理 ,我这里是git下载项目,所以选择 git ,因为是开源的,所以没有填写账号密码,如图

    3、设置构建环境,选择 Provide Node & npm bin/ folder to PATH  然后选择之前安装插件时候配置的node版本,如图

     4、配置项目自动化打包,选择 增加构建步骤 ---Excute shell  这个是运行相关的sh命令

    cd cnbi-client/
    #npm install -g cnpm --registry=https://registry.npm.taobao.org
    rm -rf dist
    rm -f dist.tar.gz
    cnpm install
    cnpm run build
    tar -zcf dist.tar.gz dist

     如下图

     5、把打包好的项目文件发布到远程服务器

    选择“构建后操作步骤”---“Send build artifacts over SSH” 。

          Name:创建的远程服务器名称(需要推送远程的服务器名称)

          Source files:本地需要传输过去的文件(默认执行路径为Jenkins的工作路径,直接跟要传输的文件名称和相对路径)

          Remove prefix:过滤掉的目录名(指过滤掉的source files路径)

          Remote directory:远程服务器的保存路径(配置的根目录的路径下生成的路径)

          Exec command:传输完成后在远程服务器执行的sh命令(默认执行路径为root家目录)

    实例:

     如有不全可参考以前做的老图:

    6、保存后点击“立即构建”查看任务是否构建完成,Console Output 菜单可以查看构建日志。

    四、遇到的问题

    1、拉取代码超时报错

    [test] $ /bin/sh -xe /tmp/jenkins5540140486901721898.sh
    + cd /var/lib/jenkins/workspace/test
    + rm -rf dist
    + npm install
    
    > yorkie@2.0.0 install /var/lib/jenkins/workspace/test/node_modules/yorkie
    > node bin/install.js
    
    CI detected, skipping Git hooks installation
    
    > node-sass@4.9.3 install /var/lib/jenkins/workspace/test/node_modules/node-sass
    > node scripts/install.js
    
    Downloading binary from https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-72_binding.node
    Cannot download "https://github.com/sass/node-sass/releases/download/v4.9.3/linux-x64-72_binding.node": 
    
    HTTP error 404 Not Found
    
    Hint: If github.com is not accessible in your location
          try setting a proxy via HTTP_PROXY, e.g. 
    
          export HTTP_PROXY=http://example.com:1234
    
    or configure npm proxy via
    
          npm config set proxy http://example.com:8080
    
    > electron@4.0.0 postinstall /var/lib/jenkins/workspace/test/node_modules/electron
    > node install.js

     需要用到淘宝镜像做代理,否则连接不上,参考:http://npm.taobao.org/

    2、推送远程服务器内存溢出

    报错信息如下:

    SSH: Connecting from host [localhost.localdomain]
    SSH: Connecting with configuration [226] ...
    SSH: Disconnecting configuration [226] ...
    FATAL: GC overhead limit exceeded
    java.lang.OutOfMemoryError: GC overhead limit exceeded
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1249)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
        at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1282)
    Finished: FAILURE

    报错信息二:

    java.lang.OutOfMemoryError: Java heap space
        at com.jcraft.jzlib.Deflate.deflateInit(Deflate.java:1384)
        at com.jcraft.jzlib.Deflate.deflateInit(Deflate.java:1326)
        at com.jcraft.jzlib.Deflater.init(Deflater.java:133)
        at com.jcraft.jzlib.Deflater.<init>(Deflater.java:80)
        at com.jcraft.jzlib.Deflater.<init>(Deflater.java:75)
        at com.jcraft.jzlib.GZIPOutputStream.<init>(GZIPOutputStream.java:46)
        at com.jcraft.jzlib.GZIPOutputStream.<init>(GZIPOutputStream.java:40)
        at com.jcraft.jzlib.GZIPOutputStream.<init>(GZIPOutputStream.java:36)
        at hudson.console.AnnotatedLargeText.writeHtmlTo(AnnotatedLargeText.java:179)
        at hudson.console.AnnotatedLargeText.writeLogTo(AnnotatedLargeText.java:147)
        at org.kohsuke.stapler.framework.io.LargeText.doProgressText(LargeText.java:264)
        at hudson.console.AnnotatedLargeText.doProgressiveHtml(AnnotatedLargeText.java:95)
        at java.lang.invoke.LambdaForm$DMH/1024337131.invokeVirtual_L3_V(LambdaForm$DMH)
        at java.lang.invoke.LambdaForm$BMH/702564452.reinvoke(LambdaForm$BMH)
        at java.lang.invoke.LambdaForm$MH/1895324968.invoker(LambdaForm$MH)
        at java.lang.invoke.LambdaForm$MH/378519084.invokeExact_MT(LambdaForm$MH)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
        at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
        at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
        at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145)
        at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535)
        at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.MetaClass$2.doDispatch(MetaClass.java:219)
        at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.MetaClass$9.dispatch(MetaClass.java:456)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
    Caused: javax.servlet.ServletException
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:797)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.MetaClass$2.doDispatch(MetaClass.java:219)
        at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.MetaClass$9.dispatch(MetaClass.java:456)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.MetaClass$4.doDispatch(MetaClass.java:280)
        at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
        at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
        at org.kohsuke.stapler.Stapler.invoke(Stapler.java:676)
        at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623)
        at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
        at jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter.doFilter(UserLanguages.java:128)
        at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
        at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:157)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:99)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
        at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
        at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
        at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
        at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:90)
        at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1700)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1667)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.eclipse.jetty.server.Server.handle(Server.java:505)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)
        at java.lang.Thread.run(Thread.java:748)

    换了另一种方法推送到远程服务器,写一个脚本文件,采用远程复制的方法(scp)

    工程配置信息如下:

    注意:从本地仓库gitlab拉取代码需要配置git凭证,参考我的另一篇文章:

    tomcat部署Jenkins并配置jdk、maven、git

    远程复制需要配置免密登陆

    Jenkins公钥和私钥文件路径如下:

    /var/lib/jenkins/.ssh/

    参考博客:

    https://blog.csdn.net/ansu2009/article/details/83584796

  • 相关阅读:
    多项式 Wannafly挑战赛22
    L. Twice Equation ACM Nanning 2017
    我们身边的大数据
    js_隔10秒发送验证码(setInterrval定时器)
    js_定时器(setInterval)
    VS调试相关
    afx_msg与消息映射机制
    ON_COMMAND,ON_MESSAGE和ON_NOTIFY的区别
    条款4:确定对象在被使用前已经被初始化
    用doxygen+graphviz生成函数调用流程图
  • 原文地址:https://www.cnblogs.com/djlsunshine/p/11059690.html
Copyright © 2020-2023  润新知