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
是不行的
[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: [1mab5f3662432c354b153a[39m[22m
Version: webpack [1m2.7.0[39m[22m
Time: [1m30863[39m[22mms
[1mAsset[39m[22m [1mSize[39m[22m [1mChunks[39m[22m [1m[39m[22m [1m[39m[22m [1mChunk Names[39m[22m
[1m[32mstatic/fonts/element-icons.b02bdc1.ttf[39m[22m 13.2 kB [1m[39m[22m [1m[32m[emitted][39m[22m
[1m[33mstatic/js/vendor.a11188574e8c22a95fd9.js[39m[22m [1m[33m1.19 MB[39m[22m [1m0[39m[22m [1m[32m[emitted][39m[22m [1m[33m[big][39m[22m vendor
[1m[32mstatic/js/app.842d7b541ae50b8e1e0d.js[39m[22m 159 kB [1m1[39m[22m [1m[32m[emitted][39m[22m app
[1m[32mstatic/js/manifest.2496bc72a04420c949f3.js[39m[22m 1.51 kB [1m2[39m[22m [1m[32m[emitted][39m[22m manifest
[1m[32mstatic/css/app.67d5653a5ceee5df23c290c1efb8acd9.css[39m[22m 173 kB [1m1[39m[22m [1m[32m[emitted][39m[22m app
[1m[32mstatic/js/vendor.a11188574e8c22a95fd9.js.map[39m[22m 8.27 MB [1m0[39m[22m [1m[32m[emitted][39m[22m vendor
[1m[32mstatic/js/app.842d7b541ae50b8e1e0d.js.map[39m[22m 806 kB [1m1[39m[22m [1m[32m[emitted][39m[22m app
[1m[32mstatic/css/app.67d5653a5ceee5df23c290c1efb8acd9.css.map[39m[22m 226 kB [1m1[39m[22m [1m[32m[emitted][39m[22m app
[1m[32mstatic/js/manifest.2496bc72a04420c949f3.js.map[39m[22m 14.7 kB [1m2[39m[22m [1m[32m[emitted][39m[22m manifest
[1m[32mindex.html[39m[22m 492 bytes [1m[39m[22m [1m[32m[emitted][39m[22m
[1m[32mstatic/xx.png[39m[22m 2.63 kB [1m[39m[22m [1m[32m[emitted][39m[22m
[1m[32mstatic/simditor-html.js[39m[22m 3.47 kB [1m[39m[22m [1m[32m[emitted][39m[22m
[1m[32mstatic/beautify-html.js[39m[22m 66.8 kB [1m[39m[22m [1m[32m[emitted][39m[22m
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