简体   繁体   中英

Permissions slave node in Jenkins with SSH agent

I have this error when I try to configure a slave node in Jenkins with SSH agent. I'am trying to connect my kvm guest. How can I resolve this

 [01/10/19 18:37:29] [SSH] Checking java version of /var/lib/jenkins/jdk/bin/java
    Couldn't figure out the Java version of /var/lib/jenkins/jdk/bin/java
    bash: /var/lib/jenkins/jdk/bin/java: No such file or directory

    [01/10/19 18:37:29] [SSH] Checking java version of java
    [01/10/19 18:37:29] [SSH] java -version returned 1.8.0_191.
    [01/10/19 18:37:29] [SSH] Starting sftp client.
    [01/10/19 18:37:29] [SSH] Copying latest remoting.jar...
    java.io.IOException: Could not copy remoting.jar into '/var/lib/jenkins' on agent
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:1109)
        at hudson.plugins.sshslaves.SSHLauncher.access$400(SSHLauncher.java:128)
        at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:866)
        at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:833)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: java.io.IOException: Could not copy remoting.jar to '/var/lib/jenkins/remoting.jar' on agent
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:1104)
        ... 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 com.trilead.ssh2.jenkins.SFTPClient.writeToFile(SFTPClient.java:103)
        at hudson.plugins.sshslaves.SSHLauncher.copyAgentJar(SSHLauncher.java:1097)
        ... 7 more
    [01/10/19 18:37:29] Launch failed - cleaning up connection
    [01/10/19 18:37:29] [SSH] Connection closed

.

I had the same problem as you.

To solve this error you have to understand two things:

1- To connect correctly to the linux slave, jenkins copy the file "remoting.jar" in the path you defined in "Remote FS root" (in the configurations of this node) in this case "var/lib/jenkins" and then run it.

2- Jenkins will do these actions as user defined in "remote user" (also in the configurations of this node).

So if this "remote user" doesn't have access to the "remote FS root" he won't be able to copy the "remoting.jar" file or execute it. So I had to enter the instance manually, change the owner of the folder "var" as "remote user" with the command:

sudo chown <remote_user>:<remote_user> /var

after what jenkins was able to copy it and execute it.

note: if you work with an ec2 node on aws then you will have to save the image after the changes and update it in the configurations of this node.

how "Remote FS root" & "remote user" should look

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM