jenkins打包vue项目,index.html引入的js文件丢失的问题?

发布于 2022-09-11 23:52:40 字数 12996 浏览 9 评论 0

目前有一个前端项目,用vue框架搭建,其中使用了一些老的jquery框架,需要在首页index.html引入静态js,如下:

<script src="./static/previewImage/dist/md5.js"></script>
<script src="./static/previewImage/dist/previewImage.min.js"></script>
<script src="./static/app-config.js"></script>

在本地通过npm run build打包后,static文件夹里面会包含首页引用的md5.jspreviewImage.min.jsapp-config.js文件,但是通过jenkins打包后,发现没有这些文件,会导致加载失败(404),jenkins,注:上能通过git获取到这些文件。

这是什么问题呢?


jenkins版本:Jenkins ver. 2.187
console log 如下:

Started by user qy
Running as SYSTEM
Building in workspace E:\Program Files (x86)\Jenkins\workspace\官网站点website
using credential 6b11ec93-d31c-4fb6-a916-e41f53ad575f
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url http://qy@192.168.1.78:1020/r/xxyPortal.git # timeout=10
Fetching upstream changes from http://qy@192.168.1.78:1020/r/xxyPortal.git
 > git.exe --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git.exe fetch --tags --force --progress http://qy@192.168.1.78:1020/r/xxyPortal.git +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 938015a33b5ba04a301ae60f364ef437ee77cab5 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 938015a33b5ba04a301ae60f364ef437ee77cab5
Commit message: "Merge branch 'qy-master'"
 > git.exe rev-list --no-walk 1439048571a7d70f2717c3b4489f3fb65c0d2088 # timeout=10
[官网站点website] $ cmd /c call C:\Windows\TEMP\jenkins6190148166153461529.bat

E:\Program Files (x86)\Jenkins\workspace\官网站点website>cd "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website" 

E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website>cnpm install 
鈭� Installed 42 packages
鈭� Linked 0 latest versions
鈭� Run 0 scripts
鈭� All packages installed (used 25ms(network 23ms), speed 0B/s, json 0(0B), tarball 0B)
[官网站点website] $ cmd /c call C:\Windows\TEMP\jenkins1290651078402786290.bat

E:\Program Files (x86)\Jenkins\workspace\官网站点website>rmdir /s/q "E:\Program Files (x86)\Jenkins\workspace\官网站点website\Publish\portal" 

E:\Program Files (x86)\Jenkins\workspace\官网站点website>rmdir /s/q "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist" 

E:\Program Files (x86)\Jenkins\workspace\官网站点website>cd "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website" 

E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website>cnpm run build 

> supper_app@1.0.0 build E:\Program Files (x86)\Jenkins\workspace\骞冲彴缁�-App鍒嗕韩椤电珯鐐筡portal\src\website
> node build/build.js

Hash: [1mf00db22d935d2af2e4db[39m[22m
Version: webpack [1m3.12.0[39m[22m
Time: [1m11293[39m[22mms
                                                  [1mAsset[39m[22m     [1mSize[39m[22m  [1mChunks[39m[22m  [1m[39m[22m           [1m[39m[22m       [1mChunk Names[39m[22m
                          [1m[32mstatic/img/poster.197964f.jpg[39m[22m   147 kB        [1m[39m[22m  [1m[32m[emitted][39m[22m         
                    [1m[32mstatic/js/0.54bfb19580a4991a8400.js[39m[22m   102 kB       [1m0[39m[22m  [1m[32m[emitted][39m[22m         vendor-async
                    [1m[32mstatic/js/1.7b32bc96dcb9ac4360c1.js[39m[22m  17.8 kB       [1m1[39m[22m  [1m[32m[emitted][39m[22m         
                    [1m[32mstatic/js/2.5a3058e59157572a2132.js[39m[22m  4.23 kB       [1m2[39m[22m  [1m[32m[emitted][39m[22m         
                    [1m[32mstatic/js/3.e125c4719789249efea4.js[39m[22m  2.38 kB       [1m3[39m[22m  [1m[32m[emitted][39m[22m         
                    [1m[32mstatic/js/4.2dee29042a0d0dd00ea9.js[39m[22m  6.32 kB       [1m4[39m[22m  [1m[32m[emitted][39m[22m         
               [1m[33mstatic/js/vendor.1eb81666f564df1f9974.js[39m[22m   [1m[33m275 kB[39m[22m       [1m5[39m[22m  [1m[32m[emitted][39m[22m  [1m[33m[big][39m[22m  vendor
                  [1m[32mstatic/js/app.8623a45b66aad1d086be.js[39m[22m  1.95 kB       [1m6[39m[22m  [1m[32m[emitted][39m[22m         app
             [1m[32mstatic/js/manifest.98b3a3504aa8c4628055.js[39m[22m  1.56 kB       [1m7[39m[22m  [1m[32m[emitted][39m[22m         manifest
    [1m[32mstatic/css/app.306ddf4bb4af722e5944f1eab4b5c649.css[39m[22m  47.1 kB       [1m6[39m[22m  [1m[32m[emitted][39m[22m         app
[1m[32mstatic/css/app.306ddf4bb4af722e5944f1eab4b5c649.css.map[39m[22m  69.2 kB        [1m[39m[22m  [1m[32m[emitted][39m[22m         
                [1m[32mstatic/js/0.54bfb19580a4991a8400.js.map[39m[22m   510 kB       [1m0[39m[22m  [1m[32m[emitted][39m[22m         vendor-async
                [1m[32mstatic/js/1.7b32bc96dcb9ac4360c1.js.map[39m[22m  28.1 kB       [1m1[39m[22m  [1m[32m[emitted][39m[22m         
                [1m[32mstatic/js/2.5a3058e59157572a2132.js.map[39m[22m  16.8 kB       [1m2[39m[22m  [1m[32m[emitted][39m[22m         
                [1m[32mstatic/js/3.e125c4719789249efea4.js.map[39m[22m  12.8 kB       [1m3[39m[22m  [1m[32m[emitted][39m[22m         
                [1m[32mstatic/js/4.2dee29042a0d0dd00ea9.js.map[39m[22m  32.5 kB       [1m4[39m[22m  [1m[32m[emitted][39m[22m         
           [1m[32mstatic/js/vendor.1eb81666f564df1f9974.js.map[39m[22m  1.13 MB       [1m5[39m[22m  [1m[32m[emitted][39m[22m         vendor
              [1m[32mstatic/js/app.8623a45b66aad1d086be.js.map[39m[22m  8.48 kB       [1m6[39m[22m  [1m[32m[emitted][39m[22m         app
         [1m[32mstatic/js/manifest.98b3a3504aa8c4628055.js.map[39m[22m  7.95 kB       [1m7[39m[22m  [1m[32m[emitted][39m[22m         manifest
                                            [1m[32mfavicon.ico[39m[22m  4.29 kB        [1m[39m[22m  [1m[32m[emitted][39m[22m         
                                             [1m[32mindex.html[39m[22m  1.38 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.

[官网站点website] $ cmd /c call C:\Windows\TEMP\jenkins2314430824390369442.bat

E:\Program Files (x86)\Jenkins\workspace\官网站点website>xcopy "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist" "E:\Program Files (x86)\Jenkins\workspace\官网站点website\Publish\portal\" /e /d /y 
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\favicon.ico
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\index.html
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\css\app.306ddf4bb4af722e5944f1eab4b5c649.css
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\css\app.306ddf4bb4af722e5944f1eab4b5c649.css.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\img\poster.197964f.jpg
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\0.54bfb19580a4991a8400.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\0.54bfb19580a4991a8400.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\1.7b32bc96dcb9ac4360c1.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\1.7b32bc96dcb9ac4360c1.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\2.5a3058e59157572a2132.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\2.5a3058e59157572a2132.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\3.e125c4719789249efea4.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\3.e125c4719789249efea4.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\4.2dee29042a0d0dd00ea9.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\4.2dee29042a0d0dd00ea9.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\app.8623a45b66aad1d086be.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\app.8623a45b66aad1d086be.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\manifest.98b3a3504aa8c4628055.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\manifest.98b3a3504aa8c4628055.js.map
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\vendor.1eb81666f564df1f9974.js
E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist\static\js\vendor.1eb81666f564df1f9974.js.map
复制了 21 个文件

E:\Program Files (x86)\Jenkins\workspace\官网站点website>exit 0 
Archiving artifacts
Finished: SUCCESS

----------------------如下是我是在jenkins工作空间项目文件下手动执行打包报错语句。注意:如果把website站点复制到jenkins同级安装路径Program Files (x86)外面,打包是可以的(如下图)。成功输出文件里面,在index.html后面会输出index.html引用的其他js文件或其他资源。
abc.png

E:\Program Files (x86)\Jenkins\workspace\website>cnpm install
| [36/42] Installing yargs-parser@^4.2.0platform unsupported babel-loader@7.1.5
› webpack@3.12.0 › watchpack@1.6.0 › chokidar@2.1.8 › fsevents@^1.2.7 Package require os(darwin) not compatible with your platform(win32)
[fsevents@^1.2.7] optional install error: Package require os(darwin) not compatible with your platform(win32)
√ Installed 42 packages
√ Linked 747 latest versions
[1/3] scripts.postinstall vue-awesome-swiper@3.1.3 › swiper@^4.0.7 run "node -e\"console.log('\\u001b[35m\\u001b[1mLove Swiper? Support Vladimir\\'s work by donating or pledging on patreon:\\u001b[22m\\u001b[39m\\n > \\u001b[32mhttps://patreon.com/vladimirkharlampidi\\u001b[0m\\n')\"", root: "E:\\Program Files (x86)\\Jenkins\\workspace\\website\\node_modules\\_swiper@4.5.1@swiper" Love Swiper? Support Vladimir's work by donating or pledging on patreon:
 > https://patreon.com/vladimirkharlampidi

[1/3] scripts.postinstall vue-awesome-swiper@3.1.3 › swiper@^4.0.7 finished in 66ms
[2/3] scripts.postinstall babel-loader@7.1.5 › webpack@3.12.0 › uglifyjs-webpack-plugin@^0.4.6 run "node lib/post_install.js", root: "E:\\Program Files (x86)\\Jenkins\\workspace\\website\\node_modules\\_uglifyjs-webpack-plugin@0.4.6@uglifyjs-webpack-plugin"[2/3] scripts.postinstall babel-loader@7.1.5 › webpack@3.12.0 › uglifyjs-webpack-plugin@^0.4.6 finished in 62ms[3/3] scripts.postinstall babel-core@6.26.3 › babel-register@6.26.0 › core-js@^2.5.0 run "node postinstall || echo \"ignore\"", root: "E:\\Program Files (x86)\\Jenkins\\workspace\\website\\node_modules\\_core-js@2.6.10@core-js"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

[3/3] scripts.postinstall babel-core@6.26.3 › babel-register@6.26.0 › core-js@^2.5.0 finished in 68ms
√ Run 3 scripts
deprecate autoprefixer@7.2.6 › browserslist@^2.11.3 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools. deprecate extract-text-webpack-plugin@^3.0.0 Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin deprecate css-loader@0.28.11 › cssnano@3.10.0 › autoprefixer@6.7.7 › browserslist@^1.7.6 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
deprecate css-loader@0.28.11 › cssnano@3.10.0 › postcss-merge-rules@2.1.2 › postcss-selector-parser@2.2.3 › flatten@^1.0.2 I wrote this module a very long timeago; you should use something else.
deprecate webpack-bundle-analyzer@2.13.1 › bfj-node4@^5.2.0 Switch to the `bfj` package for fixes and new features!
Recently updated (since 2019-10-09): 6 packages (detail see file E:\Program Files (x86)\Jenkins\workspace\website\node_modules\.recently_updates.txt)
  Today:
    → portfinder@^1.0.13(1.0.25) (05:55:01)
√ All packages installed (931 packages installed from npm registry, used 2m(network 2m), speed 14.28kB/s, json 789(1.75MB), tarball 0B)

E:\Program Files (x86)\Jenkins\workspace\website>cnpm run build

> supper_app@1.0.0 build E:\Program Files (x86)\Jenkins\workspace\website
> node build/build.js

Hash: 813e55cd0ed36b20b22f
Version: webpack 3.12.0
Time: 11300ms

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧夏天 2022-09-18 23:52:40

jenkins 的脚本以及 console 输出都贴一下。


第1次补充回答:

让你贴一下脚本咋这么懒呢……

下面是你的脚本吗?

cd "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website" 
cnpm install

rmdir /s/q "E:\Program Files (x86)\Jenkins\workspace\官网站点website\Publish\portal" 
rmdir /s/q "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist" 
cd "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website" 
cnpm run build 

xcopy "E:\Program Files (x86)\Jenkins\workspace\官网站点website\portal\src\website\dist" "E:\Program Files (x86)\Jenkins\workspace\官网站点website\Publish\portal\" /e /d /y

里面应该有个 WORKSPACE 环境变量,我就没替换了。

你说的少文件,是最后的 Publish\portal\ 目录下少、还是连 src\website\dist\ 下也少?

与他有关 2022-09-18 23:52:40

是在window环境下打包的吗, 如果是的话 可能是Jenkins工作空间路径的问题,不要把工作空间放在Program Files (x86)目录下面,参考:https://www.crazyming.com/not...

栩栩如生 2022-09-18 23:52:40

楼主 求教,你是怎么解决的,看上文没有搞明白

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文