Efficient Jenkins Master-Slave Configuration for Freestyle Project

Jenkins Master Your main Jenkins server is the Master. The Master’s job is to handle  Scheduling build jobs. Dispatching builds to the slave...





Jenkins Master

Your main Jenkins server is the Master. The Master’s job is to handle 

  • Scheduling build jobs.
  • Dispatching builds to the slaves for the actual execution
  • Monitor the slaves (possibly taking them online and offline as required)
  • Recording and presenting the build results
  • A Master instance of Jenkins can also execute build jobs directly.

    Jenkins Slave
    A Slave is a Java executable that runs on a remote machine. The following are the characteristics of Jenkins' Slaves
  • It hears requests from the Jenkins Master instance.
  • Slaves can run on a variety of operating systems.
  • The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
  • You can configure a project to always run on a particular Slave machine, or a particular type of Slave machine, or simply let Jenkins pick the next available Slave

    We can configure the slave with any operating systems. cross-platform ( Linux to Windows) also can do the slave configuration.
    Once you choose the operating system make sure both jenkins master and jenkins slave installed the same Java version.

    Once Java is Installed on the slave server, we need to Register the Slave node in Jenkins, for that we need to log in to the Jenkins Dashboard and configure it.

    Configure the Slave:
               Click Manage Jenkins --> Nodes --> Click New Node, Click the Create option to configure the slave node in jenkins


    1. Name: 

    give any name that you need to identify easily for a slave.

    2. Description

    we need to type the description.
    Optional human-readable description for this agent.

    This could include information useful to users, such as how many CPU cores the agent has, how much RAM it has installed, its physical location, etc.

    3. Number of executors

    we need to mention the executor count, 

    The maximum number of concurrent builds that Jenkins may perform on this node.

    A good value to start with would be the number of CPU cores on the machine. Setting a higher value would cause each build to take longer, but could increase the overall throughput. For example, one build might be CPU-bound, while a second build running at the same time might be I/O-bound — so the second build could take advantage of the spare I/O capacity at that moment.


    Agents (nodes that are not built-in nodes) must have at least one executor. To temporarily prevent any builds from being executed on an agent, use the Mark this node temporarily offline button on the agent's page.


    For the built-in node, set the number of executors to zero to prevent it from executing builds locally on the controller. Note: The built-in node will always be able to run flyweight tasks including Pipeline's top-level task.

    4. Remote root directory: 

    we need give the directory path of the client node(slave node), i am giving /opt/build 

    An agent needs to have a directory dedicated to Jenkins. Specify the path to this directory on the agent. It is best to use an absolute path, such as /var/jenkins or c:\jenkins. This should be a path local to the agent machine. There is no need for this path to be visible from the controller.

    5. Label: 

    The label we need to give as unique that we are going to use in the jenkins job.

    Labels (or tags) are used to group multiple agents into one logical group.

    6. Usage: 

    Controls how Jenkins schedules build on this node.

    Use this node as much as possible

    This is the default setting.

    In this mode, Jenkins uses this node freely. Whenever there is a build that can be done by using this node, Jenkins will use it.

    Only build jobs with label expressions matching this node

    In this mode, Jenkins will only build a project on this node when that project is restricted to certain nodes using a label expression, and that expression matches this node's name and/or labels.

    This allows a node to be reserved for certain kinds of jobs. For example, if you have jobs that run performance tests, you may want them to only run on a specially configured machine while preventing all other jobs from using that machine. To do so, you would restrict where the test jobs may run by giving them a label expression matching that machine.

    Furthermore, if you set the # of executors value to 1, you can ensure that only one performance test will execute at any given time on that machine; no other builds will interfere.

    7. Launch method: 

    (click websocket → Use WebSocket to connect to the Jenkins master rather than the TCP port. See JEP-222 for background.)

    If you are clicking the disable work directory you will not get the logs inside the directory.

    Controls how Jenkins starts this agent.

    Launch the agent by connecting it to the controller

    Allows an agent to be connected to the Jenkins controller whenever it is ready.

    In one mode, Java Web Start is used. In this case, a JNLP file must be opened on the agent machine, which will establish a TCP connection to the Jenkins controller. (Other launch methods use a JNLP file but not Java Web Start, or do not use a JNLP file at all.)

    This means that the agent need not be reachable from the controller; the agent just needs to be able to reach the controller. If you have enabled security via the Configure Global Security page, you can customize the port on which the Jenkins controller will listen for incoming agent connections.

    By default, the agent will launch a GUI, but it is also possible to run an agent without a GUI, for example as a Windows service.

    Launch agent via execution of command on the controller

    Starts an agent by having Jenkins execute a command from the controller. Use this when the controller is capable of remotely executing a process on another machine, e.g. via SSH or RSH.

    Launch agents via SSH

    Starts an agent by sending commands over a secure SSH connection. The agent needs to be reachable from the Jenkins controller, and you will have to supply an account that can log in on the target machine. No root privileges are required.

    8. Availability : 

    Controls when Jenkins starts and stops this agent.

    Keep this agent online as much as possible

    In this mode, Jenkins will keep this agent online as much as possible.

    If the agent goes offline, e.g. due to a temporary network failure, Jenkins will periodically attempt to restart it.

    Bring this agent online according to a schedule

    In this mode, Jenkins will bring this agent online at the scheduled time(s), remaining online for a specified amount of time.

    If the agent goes offline while it is scheduled to be online, Jenkins will periodically attempt to restart it.
    After this agent has been online for the number of minutes specified in the Scheduled Uptime field, it will be taken offline.
    If Keep online while builds are running is checked, and the agent is scheduled to be taken offline, Jenkins will wait for any builds that may be in progress to complete.
    Bring this agent online when in demand, and take it offline when idle
    In this mode, Jenkins will bring this agent online if there is demand, i.e. there are queued builds that meet the following criteria:

    • They have been in the queue for at least the specified demand delay period

    • They can be executed by this agent (e.g. have a matching label expression)

    This agent will be taken offline if:

    • There are no active builds running on this agent

    • This agent has been idle for at least the specified Idle delay period

    Click save to save the configuration.

      
    After saving the Agent go to manage jenkins → Manage nodes and clouds Click the newly created slave node you will see a few steps to connect the master to the slave node 
    If your Jenkins Ip and the Agent downloaded Ip were different then you should need to update the current public IP in the Jenkins system configuration.
    Change the jenkins host ip address to connect the agent slave to the master. Go to manage jenkins→ system → jenkins location change the current ip address

    After Changing the ip address in jenkins connecting the node should match the new ip address
    Now Download the agent.jar file from the slave server's /opt path and execute the below commands. Command: wget http://13.58.23.51:8080/jnlpJars/agent.jar
    Run the below command to connect the agent to the masterIf you want to connect in detach mode continuously we need to give " & " at the end of the command java -jar agent.jar -jnlpUrl http://13.58.23.51:8080/computer/slave%2Dnode1/jenkins-agent.jnlp -secret 78f9081fc9a41194fdd7cd11e4cc2b78fef38ca5276038828be17a73fcb90a65 -workDir "/opt/build" &

    After setting up the master server you will get the master and slave server offline issue, we need to fix that issue then only we can be able to use the master-slave.

    ERROR FIXING:
    To fix the issue click Node Monitoring change, Change the Free Disk Space Threshold from 1GB to 10MB, and click Apply and Save. 


    After updating the free space you can able to see the master back online.

    Now create the New FreeStyle Job and inside the config, we need to click the option called Restrict where this project can be run.
    Inside the label expression, we need to give our slave-node server’s label, which is already given during the slave configuration.




    Now save and build the job and check your jenkins job logs.
    Cross-verifying the build by logging the slave server and going to /opt/build Directory.

    Inside the /opt/build, we can able to see the workspace directory created inside the workspace we have a demo jenkins job created.

    The Above one was the Testing Jenkins job, if you have a freestyle job with SCM or Maven jobs you can use master-slave with your existing Jobs.


    ----------------------------------------!!!! Happy Learning with Techiev !!!!!!!!----------------------------------

    -------------------------Subscribe our Youtube Channel by clicking the below link---------------------- ----------------------------!!https://www.youtube.com/@techieview729!!---------------------
  • Name

    AWS,19,CNCF,8,Devops,37,linux,11,
    ltr
    item
    Techie View: Efficient Jenkins Master-Slave Configuration for Freestyle Project
    Efficient Jenkins Master-Slave Configuration for Freestyle Project
    https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTYrDbuSkRdITXvRjbYyxBfWAoRS5HE2L31vxpDx1-eE4TnSlvM_HbtsRNjpDpK-M32wG42uIvAvAPQgcO7J-cXIXHnbha6MwbTnDoFX5ZeXiVVayPaMuVIHf1luuQ_FAFO-TYFmZqcBH9vTWmhO0jngRl1vEZMLztdlnk59kt2d5Z1txgxMrF51EWaGmn/w640-h378/jenkins%20master-slave.png
    https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTYrDbuSkRdITXvRjbYyxBfWAoRS5HE2L31vxpDx1-eE4TnSlvM_HbtsRNjpDpK-M32wG42uIvAvAPQgcO7J-cXIXHnbha6MwbTnDoFX5ZeXiVVayPaMuVIHf1luuQ_FAFO-TYFmZqcBH9vTWmhO0jngRl1vEZMLztdlnk59kt2d5Z1txgxMrF51EWaGmn/s72-w640-c-h378/jenkins%20master-slave.png
    Techie View
    https://www.techiev.com/2024/01/efficient-jenkins-master-slave.html
    https://www.techiev.com/
    https://www.techiev.com/
    https://www.techiev.com/2024/01/efficient-jenkins-master-slave.html
    true
    7013663511659419322
    UTF-8
    Loaded All Posts Not found any posts VIEW ALL View Full Article Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy