Jenkins Slave Permission Denied while copying slave.jar
Asked Answered
T

7

15

I get a permissions denied but don't know why. From my jenkins master I was able to run the following command using ssh-rsa-key

scp /var/cache/jenkins/war/WEB-INF/slave.jar jenkins@<my_slave_host>:/var/jenkins/

Note: I did manually create /var/jenkins/ on the my slave host when i saw it didn't exist and made it owned by the jenkins user. My master jenkins is configured to use the jenkins@mySlaveHost using .ssh keys.

Any ideas why I'm getting a permissions denied? What is it trying to do?

Here's the log from master jenkins after clicking [Lauch slave agent] button:

[02/27/15 15:18:01] [SSH] Opening SSH connection to <my_slave_host>:22.
[02/27/15 15:18:02] [SSH] Authentication successful.
[02/27/15 15:18:03] [SSH] The remote users environment is:
BASH=/bin/bash
BASHOPTS=cmdhist:complete_fullquote:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_EXECUTION_STRING=set
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="3" [2]="11" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='4.3.11(1)-release'
CATALINA_HOME=/opt/tomcat/current
DIRSTACK=()
EUID=107
GROUPS=()
HOME=/var/lib/jenkins
HOSTNAME=*********** REMOVED***********
HOSTTYPE=x86_64
IFS=$' \t\n'
JAVA_HOME=/usr/lib/jvm/java-7-oracle
LANG=en_US.UTF-8
LOGNAME=jenkins
MACHTYPE=x86_64-pc-linux-gnu
MAIL=/var/mail/jenkins
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PIPESTATUS=([0]="0")
PPID=10592
PS4='+ '
PWD=/var/lib/jenkins
SHELL=/bin/bash
SHELLOPTS=braceexpand:hashall:interactive-comments
SHLVL=1
SSH_CLIENT='10.57.13.32 34436 22'
SSH_CONNECTION='10.57.13.32 34436 10.57.6.42 22'
TERM=dumb
UID=107
USER=jenkins
XDG_RUNTIME_DIR=/run/user/107
XDG_SESSION_ID=42
_=']'
[02/27/15 15:18:03] [SSH] Checking java version of java
[02/27/15 15:18:04] [SSH] java -version returned 1.7.0_76.
[02/27/15 15:18:04] [SSH] Starting sftp client.
[02/27/15 15:18:04] [SSH] Copying latest slave.jar...
hudson.util.IOException2: Could not copy slave.jar into '/var/jenkins' on slave
    at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1019)
    at hudson.plugins.sshslaves.SSHLauncher.access$300(SSHLauncher.java:133)
    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:709)
    at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:696)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: hudson.util.IOException2: Could not copy slave.jar to '/var/jenkins/slave.jar' on slave
    at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1016)
    ... 7 more
Caused by: com.trilead.ssh2.SFTPException: Permission denied (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation.)
    at com.trilead.ssh2.SFTPv3Client.openFile(SFTPv3Client.java:1201)
    at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1074)
    at com.trilead.ssh2.SFTPv3Client.createFile(SFTPv3Client.java:1055)
    at hudson.plugins.sshslaves.SFTPClient.writeToFile(SFTPClient.java:93)
    at hudson.plugins.sshslaves.SSHLauncher.copySlaveJar(SSHLauncher.java:1008)
    ... 7 more
[02/27/15 15:18:04] Launch failed - cleaning up connection
[02/27/15 15:18:04] [SSH] Connection closed.

Edit: Here's /var/jenkins on the slave:

$ ls -al
total 436
drwxr-xr-x  2 jenkins jenkins     22 Feb 27 15:17 .
drwxr-xr-x 14 root    root      4096 Feb 27 15:12 ..
-rw-r--r--  1 jenkins jenkins 439584 Feb 27 15:17 slave.jar

As for SFTP, I do not think it is enabled, can you point me to any docs that says SFTP is a pre-requisite for a slave? All the pages I've seen do not mention SFTP.

Trichromatism answered 27/2, 2015 at 22:26 Comment(2)
Could you edit your question to add the permissions and ownership on /var/jenkins on this remote server? Eg, run "ls -ld /var/jenkins" and add the output to the question? Also include the permissions of slave.jar in that directory, if there is such a file in the directory.Thenceforward
So far as I can see from your log - Jenkins is using SFTP and you personally is using SCP. You could also try to transfer some file via SFTP in order to reproduce the issues that Jenkins is encountering.Credent
I
12

It looks like the problem is tied to your Remote root directory setting. That needs to be the location of the slave.jar, as Jenkins will try to execute it from there.

As for the permissions, the Remote Root Directory (whatever you set it to) needs to be configured to allow Jenkins to access it.

Therefore, if you change your Remote root directory setting to be /var/jenkins/ in your case, it should launch the Jenkins slave successfully.

Intrepid answered 5/3, 2015 at 18:58 Comment(2)
Not working for me. Both slave and master have same jenkins path /var/lib/jenkins. SSH is also connecting fine and permissions are also correct.I am missing something.Please help [![Slave][1]][1] [![Master][2]][2] [1]: i.sstatic.net/fcBnw.png [2]: i.sstatic.net/BEbhC.pngSequacious
You should start your own question with more data added. Your problem may be different than mine.Trichromatism
I
4

Granting

sudo chmod -R 777 /var/lib/jenkins 

works for me

Insured answered 17/2, 2018 at 14:24 Comment(4)
For a windows agent, right click C:\Jenkins -> properies -> security -> then add the service user that jenkins logs in as with Full ControlSipes
Works for me too but what is this doing exactly?Goshorn
It gives Read, Write and Execute permissions to /var/lib/jenkins directory for all usersLowborn
Opening files with chmod -R 777 is not safe. This is a security risk.Wingard
L
3
sudo chmod -R 777 /var/jenkins      
Lightner answered 25/5, 2017 at 10:34 Comment(0)
F
2

Make sure that the location's permissions where the jar needs to be copied is as the logged in user (i.e. jenkins).

check for permisison using:

ls -l directory_name

Most probably you'll find another owner, so change the owner with:

chown -R username:username directory_name

That worked for me !

Fading answered 10/5, 2021 at 17:26 Comment(0)
R
0

For anyone with an external drive, check that it's mounted correct:

drwxrwxrwx+  2 App   admin   68 Aug 25 19:33 Jenkins_Support
drwxrwxr-x  19 App   staff  714 Sep 25 10:46 Jenkins_Support 1

This might be a problem

Repent answered 25/9, 2017 at 9:7 Comment(0)
C
0

If you changed a user to connect to slave, please also make sure slave destination directory is empty (not containing slave.jar copied there by previous user). This is kind of stupid, but costed me a time.

Cuthbert answered 28/9, 2018 at 9:46 Comment(0)
C
-1

In ubuntu terminal check

service ufw status

if active

service ufw stop

In redhat terminal check

service iptables status

if active

service iptables stop service ip6tables status if active service ip6tables stop

then check jenkins-slave-node status

Cupidity answered 17/12, 2021 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.