记一次内网jenkins自动发布血泪史

4 篇文章 0 订阅
2 篇文章 0 订阅

我们公司开发环境为内网环境,因此在开发或者测试流程上都有不可预知的问题等着。这次我使用vue3开发前端,需要在jenkins上设置自动化部署,使测试可以一键点击部署。

环境介绍

开发环境

  • 操作系统:win10
  • node版本:V14.15.1

测试环境

  • 操作系统:CentOS6.5
  • node版本:V10.8.0

问题汇总

测试环境无法使用V10.8.0编译Vue3

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (D:\Project\sjjk-web\node_modules\vite\dist\node\chunks\dep-971d9e33.js:25:20)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

因为个人电脑node版本太低所以导致报了该错误,需要升级到开发环境的node版本V14.15.1,这时又遇到了第二个问题。

CentOS6.5不支持安装nodeV14.15.1版本

node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.16' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by node)

CentOS6.5竟然缺少glibc网上确实有一些案例进行升级libstdc++.so.6,由于个人对于linux的属性程度没有那么好,因此我没有对操作系统的库进行升级,而是选用公司内网中其他的一台CentOS7的服务器。想通过配置Jenkins的Send files or execute commands over SSHExecute Shell script on remote host using ssh两个功能操作远程服务器。

使用npm run build命令使报esbuild不是当前平台版本

You installed esbuild on another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.

Specifically the "esbuild-windows-64" package is present but this platform
needs the "esbuild-linux-64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.

由于内网没有搭建npm私服,基本上每个项目都是从外网下完包后拷到内网开发。在配置Jenkins时我将当前项目使用的node_modules拷贝到Jenkins的workspace目录下对应的当前项目目录中。Jenkins原理就是pull远程git上设定的分支,然后执行设定的命令。根据这原理我投机取巧就把node_modules直接拷贝进去。结果看了下node_modules中的esbuild版本果然是esbuild-windows-64,这可怎么办呢,根据报错看了下esbuild源码,基本上就是根据不同的平台加载不平台版本的esbuild-平台包,我想直接下包不就可以了吗,结果打开npm官网后,不让下载那个linux平台的包,最后只好找个公共上网机安装了CentOS7虚拟机,重新下载包后放到内网服务器对应的目录下。

使用tar命令打包整个项目时丢失以.开头的项目内部文件

项目根目录中包含.env,.env.development,.env.production环境变量文件。我的发布项目流程是:
Jenkins服务器拉取代码=》所有代码打tar包=》发送到远程服务器(CentOS7系统)=》远程服务器解压tar包=》使用npm命令进行build=》将打包后的文件拷贝到nginx中
最后结果为访问nginx后路径跳到http://ip:port/undefind/项目名,这是由于在配置路径时我使用了环境变量文件中的文件,问题就出在第二步所有代码打tar包,在打包的时候使用tar -zcvf 项目.tar.gz *进行打包,结果该命令无法将.开头的文件添加到tar包。网上查找后可以使用tar -zcvf 项目.tar.gz * .[!.]*


在Jenkins点击立即构建OK了,nginx配置就不写了。
内网开发真的会遇到很多无法处理的问题,可能外网开发很简单就可以解决的问题,在内网环境很难处理。以上为我自己在内网配置Jenkins构建vue3遇到的问题,可能有些问题会有更好的解决方案,希望大家可以帮我指正,感激,感激,感激!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值