我想盡一切辦法在 Kubernetes 上運行的 Jenkins 管道中使用 NPM 構建一個 ReactJs 應用程式。
當我嘗試從 Windows 或什至從帶有 Ubuntu 安裝的 Linux 的 Windows 子系統構建我的專案時,一切正常,并且 NPM 能夠安裝包并從 package.json 檔案構建專案。
我安裝了 NodeJS 插件(可在此處獲得)并將此部分添加到我的 Jenkinsfile 中
stages {
stage('Build') {
steps {
nodejs(nodeJSInstallationName: 'nodeJS_14.15.4') {
sh """
cd ./project-folder
npm install
npm run-script build
"""
}
}
}
}
我使用以下package.json
{
"name": "app-react",
"version": "5.0.0",
"homepage": ".",
"private": true,
"dependencies": {
"react": "^17.0.1",
...
"react-scripts": "4.0.0",
...
},
"scripts": {
"start": "set HTTPS=true&&react-scripts start",
"build": "set GENERATE_SOURCEMAP=false&&react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sitemap": "babel-node src/sitemap-generator.js"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1"
}
}
安裝似乎沒問題,但是在構建步驟總是失敗。使用藍海我可以看到以下錯誤訊息
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apollo-react@5.0.1 build: `set GENERATE_SOURCEMAP=false&&./node_modules/react-scripts/bin/react-scripts.js build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the apollo-react@5.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-12-04T19_05_34_235Z-debug.log
script returned exit code 1
可訪問 /root/.npm/_logs 的完整日志向我展示了這一點:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run-script', 'build' ]
2 info using npm@6.14.10
3 info using node@v14.15.4
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle app-react@5.0.0~prebuild: app-react@5.0.0
6 info lifecycle app-react@5.0.0~build: app-react@5.0.0
7 verbose lifecycle app-react@5.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle app-react@5.0.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/jenkins/agent/workspace/client/app-react/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle app-react@5.0.0~build: CWD: /home/jenkins/agent/workspace/client/app-react
10 silly lifecycle app-react@5.0.0~build: Args: [ '-c', 'set GENERATE_SOURCEMAP=false&&react-scripts build' ]
11 silly lifecycle app-react@5.0.0~build: Returned: code: 1 signal: null
12 info lifecycle app-react@5.0.0~build: Failed to exec build script
13 verbose stack Error: app-react@5.0.0 build: `set GENERATE_SOURCEMAP=false&&react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1048:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid app-react@5.0.0
15 verbose cwd /home/jenkins/agent/workspace/client/app-react
16 verbose Linux 4.15.0-135-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run-script" "build"
18 verbose node v14.15.4
19 verbose npm v6.14.10
20 error code ELIFECYCLE
21 error errno 1
22 error app-react@5.0.0 build: `set GENERATE_SOURCEMAP=false&&react-scripts build`
22 error Exit status 1
23 error Failed at the app-react@5.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
在此之前,我還嘗試使用其他代理構建我的專案,實際上在使用 NodeJs 插件進行測驗之前的腳本中,我使用了 Kubernetes 插件,該插件可以將任何代理運行到臨時 pod 中。因此,我嘗試使用 Nodejs 映像,甚至使用手動安裝 NodeJs 的 Ubuntu 映像。結果總是和以前一樣。
我不知道問題的根源是什么:對已安裝包的訪問?資源問題?
uj5u.com熱心網友回復:
我終于找到了解決方法。構建失敗不是因為錯誤而是警告。
解決方法是去掉eslint配置部分
"eslintConfig": {
"extends": "react-app"
}
當 eslint 不活動時,構建的結果是Compiled successfully。
但是當它處于活動狀態時,結果是Compiled with warnings并且所有警告都出現在日志中,并且 jenkins 作業失敗。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/375368.html
標籤:节点.js 反应 詹金斯 Kubernetes 新产品经理
下一篇:有沒有辦法將CloudFunctions直接作為zip工件部署到GoogleCloudPlatform?而不依賴于默認的CloudBuild?
