Jenkins自动构建vue项目

2022-12-05 15:46:29 浏览数 (1)

Jenkins安装 请参考:https://cloud.tencent.com/developer/article/2186451

ssh连接gitee

代码语言:javascript复制
#生成公钥,私钥
root@edfd04c7ec00:/# ssh-keygen -t rsa -C "jenkins"

公钥配到gitee:https://gitee.com/profile/sshkeys

私钥配到Jenkins:Dashboard -> 系统管理 -> 凭据 -> 系统 -> 全局凭据 (unrestricted)

如上配置完,在拉取项目(git@gitee.com:chudaozhe/enterprise-admin.git)时,可能报错

代码语言:javascript复制
returned status code 128:
stdout: 
stderr: No ECDSA host key is known for gitee.com and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

这时,配置一下Git Host Key Verification Configuration就可以了

构建vue项目

配置nodejs

Dashboard -> 系统管理 -> 插件管理 -> 可选插件

搜索“nodejs”,安装即可

接着,Dashboard -> 系统管理 -> 全局工具配置

配置https://mirrors.aliyun.com/nodejs-release/

接着,测试一下

成功了

如上,是成功了,但因为没有加到环境变量,所以直接执行node -v是不行的

代码语言:javascript复制
[root@nfsFileSystem vagrant]# node -v
bash: node: command not found
[root@nfsFileSystem vagrant]# /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs19/bin/node -v
v19.2.0

clone并构建vue项目

配置shell脚本

代码语言:javascript复制
npm install --registry=https://registry.npm.taobao.org
npm run build

构建成功,会多一个dist目录

日志

代码语言:javascript复制
First time build. Skipping changelog.
Unpacking https://mirrors.aliyun.com/nodejs-release/v19.2.0/node-v19.2.0-linux-x64.tar.gz to /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs19 on Jenkins
[vue_admin] $ /bin/sh -xe /tmp/jenkins9582283174751732397.sh
  npm install --registry=https://registry.npm.taobao.org
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
...
added 1019 packages in 50s
  npm run build

> vue_admin@1.0.0 build
> node build/build.js

(node:5656) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5656) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
...
Starting to optimize CSS...
Processing static/css/app.67d5653a5ceee5df23c290c1efb8acd9.css...
Processed static/css/app.67d5653a5ceee5df23c290c1efb8acd9.css, before: 176458, after: 173025, ratio: 98.05%
Hash: ab5f3662432c354b153a
Version: webpack 2.7.0
Time: 30863ms
                                                  Asset       Size  Chunks                    Chunk Names
                 static/fonts/element-icons.b02bdc1.ttf    13.2 kB          [emitted]         
               static/js/vendor.a11188574e8c22a95fd9.js    1.19 MB       0  [emitted]  [big]  vendor
                  static/js/app.842d7b541ae50b8e1e0d.js     159 kB       1  [emitted]         app
             static/js/manifest.2496bc72a04420c949f3.js    1.51 kB       2  [emitted]         manifest
    static/css/app.67d5653a5ceee5df23c290c1efb8acd9.css     173 kB       1  [emitted]         app
           static/js/vendor.a11188574e8c22a95fd9.js.map    8.27 MB       0  [emitted]         vendor
              static/js/app.842d7b541ae50b8e1e0d.js.map     806 kB       1  [emitted]         app
static/css/app.67d5653a5ceee5df23c290c1efb8acd9.css.map     226 kB       1  [emitted]         app
         static/js/manifest.2496bc72a04420c949f3.js.map    14.7 kB       2  [emitted]         manifest
                                             index.html  492 bytes          [emitted]         
                                          static/xx.png    2.63 kB          [emitted]         
                                static/simditor-html.js    3.47 kB          [emitted]         
                                static/beautify-html.js    66.8 kB          [emitted]         

  Build complete.

  Tip: built files are meant to be served over an HTTP server.
  Opening index.html over file:// won't work.

Finished: SUCCESS

参考

https://blog.csdn.net/qq_39905409/article/details/122449380

0 人点赞