我正在尝试在Ubuntu 18.04上部署可正常运行的Windows 10 Spring-Boot / React应用程序,但是尽管进行了无数次尝试修复,但仍会出现“ react-scripts:Permission denied”错误。希望你们中的一位反应专家可以发现我的错。
我的package.json看起来像这样
{ "name": "medaverter-front", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", "axios": "^0.19.2", "bootstrap": "^4.4.1", "react": "^16.13.0", "react-dom": "^16.13.0", "react-router-dom": "^5.1.2", "react-scripts": "3.4.0", "react-table-6": "^6.11.0", "react-validation": "^3.0.7", "reactstrap": "^6.5.0", "validator": "^12.2.0" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
我以root用户身份登录,并使用nvm来安装node和lts。我这样安装nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
然后这样做:
nvm install node nvm use node nvm install --lts nvm use --lts
然后,我cd要/var/lib/jenkins/workspace/MedAverter/medaverter- front安装node_modules这样的:
cd
/var/lib/jenkins/workspace/MedAverter/medaverter- front
node_modules
npm install -g
然后将其递归更改为777,如下所示:
chmod -R 777 node_modules
我还递归地将所有/root/.nvm权限更改为777,如下所示:
chmod -R 777 /root/.nvm
我可以使用一次构建它
npm run build
但是后来我从詹金斯那里运行了“立即构建”,但失败了
[[1;34mINFO[m] Running 'npm run build' in /var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] > react-scripts build [[1;34mINFO[m] [[1;31mERROR[m] sh: 1: react-scripts: Permission denied [[1;31mERROR[m] npm ERR! code ELIFECYCLE [[1;31mERROR[m] npm ERR! errno 126 [[1;31mERROR[m] npm ERR! medaverter-front@0.1.0 build: react-scripts build [[1;31mERROR[m] npm ERR! Exit status 126
[[1;34mINFO[m] Running 'npm run build' in
/var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] > react-scripts build [[1;34mINFO[m] [[1;31mERROR[m] sh: 1: react-scripts: Permission denied [[1;31mERROR[m] npm ERR! code ELIFECYCLE [[1;31mERROR[m] npm ERR! errno 126 [[1;31mERROR[m] npm ERR! medaverter-front@0.1.0 build: react-scripts build [[1;31mERROR[m] npm ERR! Exit status 126
react-scripts build
然后我cd去/var/lib/jenkins/workspace/MedAverter/medaverter-front跑步
/var/lib/jenkins/workspace/MedAverter/medaverter-front
并且也再次得到相同的错误:
> root@ubuntu-s-1vcpu-1gb- nyc1-01:/var/lib/jenkins/workspace/MedAverter/medaverter-front# > npm run build > > > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front > > react-scripts build > > sh: 1: react-scripts: Permission denied npm ERR! code ELIFECYCLE > npm ERR! errno 126 npm ERR! medaverter-front@0.1.0 build: > react-scripts build npm ERR! Exit status 126
> root@ubuntu-s-1vcpu-1gb-
nyc1-01:/var/lib/jenkins/workspace/MedAverter/medaverter-front# > npm run build > > > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front > > react-scripts build > > sh: 1: react-scripts: Permission denied npm ERR! code ELIFECYCLE > npm ERR! errno 126 npm ERR! medaverter-front@0.1.0 build: > react-scripts build npm ERR! Exit status 126
我花了几天的时间试图弄清楚这一点。有什么建议吗?
我终于找到了解决这个问题的方法。花了几天的时间。首先,我删除了Jenkins项目,并使用Pipeline而不是Freestyle创建了一个新项目。然后,我添加了带有脚本的Jenkinsfile。那继续失败,但是现在我可以灵活地添加其他命令来处理错误。
一个新的错误是关于玩笑的工人。我在DigitalOcean服务器上运行了以下命令以超越该命令:
yarn add jest-worker
然后我又遇到了旧的权限错误。我认为所有这些权限错误都是由于用户jenkins试图运行root用户拥有的内容而引起的,即使所有内容都具有777权限。我不明白,但这就是我的解决方法。修改/ etc / sudoers文件并添加以下行:
jenkins ALL=(ALL) NOPASSWD:ALL
然后修改Jenkins文件脚本,以包括递归chmod和chown。这是最终工作的完整脚本:
pipeline { agent any stages { stage('Checkout') { steps { echo 'Checkout...' sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front' checkout scm sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front' sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front' stash 'sources' } } stage('Build') { steps { echo 'Build...' unstash 'sources' sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front' sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front' sh 'mvn clean package -DskipTests' stash 'sources' } } } }
我还不得不将DigitalOcean Droplet的内存从1GB增加到2GB,以克服另一个错误。如果有人知道更好的方法来克服令人沮丧的权限错误,请发表评论。