cannot connect Jenkins slave with master - jenkins

I have installed a Jenkins master on my Mac OS, version is 2.90.
I have installed a Jenkins slave on my ubuntu, and created a user called jenkins at /home/jenkins.
I have copied my pub key from master to slave and using
ssh jenkins#slave_ip
I can login from master to slave with no password.
However, I cannot create a new slave at Jenkins, it has the following issues:
1. Launch method does not have option "Launch slave agents via SSH",therefore I cannot set credentials.
2. since launch method only has "Launch agent via execution of command on the master" and another option for windows, I input Launch command as: ssh -v jenkins#slave_ip.
but master cannot connect with slave.
To troubleshoot, I login slave manually, I see master does ssh to slave successfully. as it shows:
sudo tail -f /var/log/auth.log:
Nov 19 00:10:32 ip-172-31-18-180 sshd[8908]: Accepted publickey for
jenkins from my_master_ip port 62411 ssh2: RSA
80:23:0e:1b:34:c1:90:52:a6:df:d0:24:6f:10:80:73
Nov 19 00:10:32 ip-172-31-18-180 sshd[8908]: pam_unix(sshd:session):
session opened for user jenkins by (uid=0)
so I doubt maybe Jenkins credential is not set because master does not send private key to slave. (I do not have this option in my Jenkins UI)
what should I do? how to make Launch method option "Launch slave agents via SSH" show, so that I can input credential of master?

you should use Launch slave agents via SSH to connect the ubuntu as slave.
you should install https://wiki.jenkins.io/display/JENKINS/SSH+Slaves+plugin
than add the Host & Credentials

Related

Can Jenkins Slave machine be configured for two different servers

Hello At work we have 2 Jenkins servers but at the moment we have limited slaves machines , I was asked to make a research if its possible to configure a slave machine for 2 different servers ?
so if I would use a machine as a slave I would do these steps:
1-Install Jenkins on the slave machine.
2-On the Jenkins master, go to "Manage Jenkins" and then click on "Manage Nodes".
3-Click on "New Node" to create a new slave node.
4-Give your slave node a name and select "Permanent Agent" as the type.
5-Click "OK" to create the slave node.
6-On the slave machine, open a terminal and navigate to the Jenkins home directory. This is typically located at /var/lib/jenkins on Linux machines.
7-java -jar slave.jar -jnlpUrl https://<Jenkins_URL>/computer/<Node_Name>/slave-agent.jnlp -secret <Node_Secret>
Replace <Jenkins_URL> with the URL of your Jenkins server, <Node_Name> with the name of your slave node, and <Node_Secret> with the secret that was generated for the slave node on the Jenkins master.
8-The slave agent should now be connected to the Jenkins master and ready to run build tasks.
why can't I do the same steps twice for two different servers , can you explain why it's not possible ?
It is possible but you have to configure them differently.
Both applications are same so windows/java by default thinks it as reconnection instead of new instance. Not sure but this can work by renaming your jnlp files.
Both the application needs to configure to use different IP to avoid connection error.

want to add a jenkins slave as a different user say "UserX"

I have logged-in to Jenkins UI using my Unix credentials (pmandal).
Then I have added a slave node (Slave1).
Now when i "Launch slave", it tries to ssh from the MASTER to the Slave(Slave1) as "jenkins" USER, and ssh fails.
My requirement is: I want the ssh from the MASTER to the Slave as a different user say "UserZ", coz i want all my operations to be performed as UserZ.
But i am unable to do so.
So my main question here is : "How to i make the MASTER to ssh to the Slave as UserZ"?
Any help would be appreciated.jenk
create the credentials in jenkins store.
This can be done from https://<yourjenkins.url>/credentials/store/system/domain/_/newCredentials
connect the node with the option "launch agent agents via ssh jenkins". From the config page of the node, you can select the credentials you just created
Note: the option "launch agent agents via ssh jenkins" is the recommended way to connect unix/linux machines: https://support.cloudbees.com/hc/en-us/articles/115003929412-How-to-create-an-agent-in-Linux-from-console

Jenkins - Run job when new slave connects

I have a Jenkins installation uses SWARM to connect new slaves.
I bring up new instances in AWS and they use the SWARM Client to connect to the Jenkins master and register themselves as slaves.
Is it possible to have the Jenkins Master detect when a new slave is added and start to run some "init" job on that slave?
Thanks
We use the Slave Setup Plugin to mount a network drive and copy some files from the master whenever a slave connects.
If you want to run certain Jenkins jobs whenever a slave (or certain slave) connects, you could try the Startup Trigger Plugin.
There is the EC2 plugin which will spin up slaves on your behalf and run an init script on them for you.
Init script is the shell script to be run on the newly launched EC2
instance, before Jenkins starts launching a slave agent. If the AMI
doesn't have Java pre-installed, you can do this in the init script.
This is also a good place to install additional packages that you need
for your builds and tests. The init script is located at /tmp/init.sh
and is owned and run by the user account specified in the "Remote
User" field (so use of "sudo" may be required for non-root accounts).

In jenkins not able to connect to slave

In master- slave the after running the jar for the slave from command prompt it is displaying connected but in the Jenkins it is displaying not getting connected to the slave The jenkins is deployed on linux server and trying to connect to slave from windows server by running slave jar
Manage Jenkins > Manage Nodes > See listed nodes and click on the slave name. You should be able to Launch agent from browser on slave.
If an error occurs, paste the error message here.

Jenkins build slave appears offline but slave service is up and Running

I am having trouble that Jenkins home page shows the Build slave is offline. But when I actually log in to build slave server, the slave service is up and running.
I am using Windows 2003 OS for all my Build slaves and Master server. The only way to get it online is to restart the service again.
Follow the given steps, you will not required to restart the services.
Goto Jenkins -> Manage Jenkins -> Manage Nodes
This will show you the list configured nodes.
In which
Build Slave -> Launch Slave Agent (Where "Build Slave" is your slave node.)
This will work if your slave is configured properly and connected with the services.
Jenkins master need communicate with Slave with ssh connection if master and slave are not in the same node.
Double check if master's ssh public key is in slave's ~/.ssh/authorized_keys.

Resources