我有一个'hello world‘NodeJS项目,我正在尝试构建一个全新的Jenkins安装(在数字海洋服务器上的Ubuntu18.04.3LTS上运行)。我对Linux的经验有限,所以请让我知道我在这里遗漏了什么。
Jenkins构建“执行shell":
whoami
npm install
./script/testJenkins控制台输出:
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项目上选择"Build Now“,紧接着我再次运行:
$ls -l test
-rw-r--r-- 1 jenkins jenkins 51 Sep 22 07:50 test我还尝试向整个jenkins文件夹或仅向测试文件授予递归权限,但都失败了:sudo chmod -R 757 /var/lib/jenkins或sudo chmod -R 757 /var/lib/jenkins/workspace/node-app/script/test
我已经在jenkins中重新申请并重新保存了我的配置,就像在另一个线程中建议的那样,但没有任何更改。
因此,构建过程中的某些内容是重置权限-如何确保jenkins用户保留运行此脚本的正确权限?
发布于 2019-09-24 18:42:45
所以我找到了答案,我希望这对其他人有帮助- git也将可执行权限保存在GitHub中,所以在我的例子中,每次Jenkins提取最新的代码时,它都会覆盖保存在git代码库中的权限。我最初在Windows上工作,所以我没有意识到这会成为一个问题。
为了解决这个问题,我只需克隆存储库,更改权限并再次提交:
$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 pushhttps://stackoverflow.com/questions/58047230
复制相似问题