Can Jenkins Slave machine be configured for two different servers - jenkins

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.

Related

Unable to see launch slave agents on Unix machines via SSH on Jenkins

I have two different Jenkins instances with different versions.
One has version 1.609.1 and when I create a slave on it I see options in the launch method like:
"Launch slaves agents on a Unix machine via SSH"
"Launch slave agents via Java web start"
"Launch slaves via execution of command on the master and let Jenkins control this Windows slave as a Windows service"
I have one more instance that is of version 2.89.4, but the slave launch option is different - it has one *"Launch slaves agent via SSH". The rest of the all options are the same.
Is this slave launching option something version-specific?
It is specific to the plugin. You need to add it in your missing instance. See SSH Slaves Plugin.

Switch Jenkins Slave to a Different Master

I have a simple Jenkins master/slave set-up but I'd like to be able to switch which master the slave points at.
Is it possible to do this by changing some config on the slave?
For a Windows Slave configuration remove the JNLP Slave for Master1/Slave node by
1. Stopping the Jenkins Slave Windows service
2. Launch a Command Prompt as an Administrator
3. then use sc delete jenkins_service_name
For OS X check out https://github.com/rhwood/jenkins-slave-osx/wiki/Uninstall
Now open a browser on the slave machine and go to your Jenkins master2 server url then Jenkins -> Manage Jenkins -> Manage Nodes -> Node (assuming the node is already setup on master2 server) and click on the Launch button to launch agent from browser on slave machine. You prob. know how to do this already. If not use this guide https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines
Maybe you can try having the slave setup on both master1 and master2 by
1. Skip my delete steps above
2. open a browser on the slave machine and go to your Jenkins master2 server url then Jenkins -> Manage Jenkins -> Manage Nodes -> Node (assuming the node is already setup on master2 server) and click on the Launch button to launch agent from browser on slave machine.
3. Instead do "Save File" and click ok in step 5b from https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines
4. Save the slave-agent.jnlp to a new folder. I'm sure the two agents will run on that slave machine without interfering each other.
Definitely. If you want to be able to switch the slave back and forth between two masters, you can set up a second slave agent on the slave machine. Steps to do this depend on the type of slave (JNLP, remote ssh, etc). Disconnect the slave from the old master using the Manage Slaves page, and shut down the first slave agent on the slave machine. Start your second slave agent, and add that slave to the second master.
You can actually have both slave agents running and have the slave be connected to both masters, although they won't know anything about each other and could both send a job to the slave at the same time regardless of the number of executors.

Jenkins - How to build a master job in slave machine?

Initially, I configured the master and slave connection setup in windows machine by launching Java web start method. And then Created a Job in Master machine. Now my question is how to assign a master job to slave machine to build the job. Please provide me the steps to follows. Thanks you.
And please let me know is slave machine requires master machine URL for Connecting Master Slave Connection setup?
You can tie your job on whichever slave you want.
There is option of "Restrict where this project can be run", You can provide jenkins slave name on which this job should always run.
Answer to your last doubt. There is standard methods to connect slave to master, it depends how are you connecting the slave to master.

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.

Jenkins Master/Slave configuration

I've been reading about Jenkins master/slave configurations but I still have some questions:
Is it so that the slave Jenkins is not actually installed and started up the way master Jenkins is? I assumed I would install one master Jenkins and another slave Jenkins in the same way, and then master Jenkins would control the slave e.g. through SSH? So I cannot view the slave Jenkins through a GUI?
The reason why I have thought about adding a slave Jenkins on another VM is because the VM contains our application servers (many test environments). Deploying and starting/stopping application servers from master Jenkins is a pain because master Jenkins and application servers are on different machines. Therefore, if I would add a slave Jenkins to the machine where our application servers are, these would actually be deployed and started/stopped locally (by slave Jenkins). I wonder if I have missed something, of if my presumptions are still valid.
In a standard Jenkins master/slave setup, Jenkins is only installed on the master. That is where you see the user interface and start/configure build jobs.
The slaves execute the jobs. There is no Jenkins installation here other than a small Java app to have Jenkins communicate to/from the slave. Jenkins talks to these slaves through the slave.jar app over e.g. SSH via the SSH Slaves Plugin and can monitor if the slave is running, etc.
So in your case, you can start jobs from the master that will execute on the application servers.
The master/slave setup also allows you to host all whole bunch of different slaves, with different OSes, different hardware, etc. You can communicate job results (artifacts) from one slave to another via the Copy Artifacts Plugin.
There are also ways to duplicate the actual Jenkins master with load balancing in a heavy use scenario. That is not what you seem to be looking for.

Resources