node.js - 如何阻止 Jenkins 在每次构建后重置用户权限?

标签 node.js linux jenkins permissions

我有一个“hello world”NodeJS 项目,我正在尝试在全新安装的 Jenkins 上构建(在 Digital Ocean 服务器上的 Ubuntu 18.04.3 LTS 上运行)。我对 Linux 的经验有限,所以请让我知道我在这里遗漏的任何内容。

Jenkins 构建“执行 shell”:

whoami
npm install
./script/test

Jenkins 控制台输出:

Started by user twulz
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/node-app
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/Twulz/node-app.git # timeout=10
Fetching upstream changes from https://github.com/Twulz/node-app.git
 > git --version # timeout=10
 > git fetch --tags --progress -- https://github.com/Twulz/node-app.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 81d9f909cfd34cd5eb65a123dd9f2a1e67686512 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 81d9f909cfd34cd5eb65a123dd9f2a1e67686512
Commit message: "Solve vulnerabilities"
 > git rev-list --no-walk 81d9f909cfd34cd5eb65a123dd9f2a1e67686512 # timeout=10
[node-app] $ /bin/sh -xe /tmp/jenkins4626689890347957662.sh
+ whoami
jenkins
+ npm install
audited 12356 packages in 4.203s
found 0 vulnerabilities

+ ./script/test
/tmp/jenkins4626689890347957662.sh: 4: /tmp/jenkins4626689890347957662.sh: ./script/test: Permission denied
Build step 'Execute shell' marked build as failure
Finished: FAILURE

所以我认为问题是jenkins用户没有执行测试脚本/var/lib/jenkins/workspace/script/test的权限。

在命令行上,我运行了这些命令来尝试更改权限:

$cd /var/lib/jenkins/workspace/node-app/script
$ls -l test
-rw-r--r-- 1 jenkins jenkins 51 Sep 22 07:30 test
$sudo chmod -R 757 /var/lib/jenkins/workspace/node-app
$sudo systemctl restart jenkins
$ls -l test
-rwxr-xrwx 1 jenkins jenkins 51 Sep 22 07:35 test

然后在我再次运行后立即在我的 jenkins 项目上选择“立即构建”:

$ls -l test
-rw-r--r-- 1 jenkins jenkins 51 Sep 22 07:50 test

我还尝试对整个 jenkins 文件夹或仅对测试文件授予递归权限,但两者仍然失败:sudo chmod -R 757/var/lib/jenkinssudo chmod -R 757/var/lib/jenkins/workspace/node-app/script/test

我已经按照另一个线程中的建议在 jenkins 中重新应用并重新保存了我的配置,但没有任何变化。

所以构建过程中的某些东西正在重置权限 - 我如何确保 jenkins 用户保留运行此脚本的正确权限?

最佳答案

所以我找到了答案,我希望这对其他人有帮助——git 也在 GitHub 中保存了可执行权限,所以在我的例子中,每次 Jenkins 提取最新代码时,它都会覆盖 git 存储库中保存的权限。我最初在 Windows 中工作,所以我没有意识到这会是一个问题。

为了解决这个问题,我只需要克隆 repo,更改权限并再次提交:

$git clone https://github.com/Twulz/node-app.git
$sudo chmod -R 757 node-app
$cd node-app/
$git add .
$git status
$git commit -m "Update execute permissions"
$git push

关于node.js - 如何阻止 Jenkins 在每次构建后重置用户权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58047230/

相关文章:

javascript - npm kafka- Node : Close consumer after final message read

javascript - 在 Docker 容器中调试 nodejs 应用程序

c - 将整数传递给子进程

linux - Yum 在 'Loading mirror speeds' 或 'Setting package sacks' 卡住

docker - 如何在 Jenkinsfile 中使用 docker image 内部环境变量?

reactjs - 如何通过Jenkins从Docker容器中获取构建目录?

docker - 如何在 Jenkins 声明式管道中从 docker hub 推送和拉取

mysql - 类型错误 : Cannot read property 'findOne' of undefined while using sequelize in node

linux - 使用 Windows 批处理通过 OpenSSH 远程连接到 Linux

javascript - 如何从浏览器向 Node 脚本发送数据?