Setup Distributed Architecture in Jenkins(Running iOS/Mac OS Builds)
In this article, we are going to set up Jenkins for running iOS/ Mac OS builds.
GOAL
As we know, we require apple hardware in order to run Mac/iOS builds. If you host Jenkins CI server in Linux machine, it is not capable of running Mac/iOS builds. Therefore, we need to create a distributed system(master/slave architecture) so that slave will be capable of running Mac/iOS builds.
Master → Linux Server(the remote machine where you host Jenkins)
Slave → Your Mac (where you build projects)
Setup
- Download Jenkins and host on a remote machine.
- Type Jenkins address in the browser and you will see the screen below:
- After Login, you can see the dashboard.
Configure Slave Node in Jenkins
- Go to Jenkins → Manage Jenkins → Manage Nodes
- Click on New Node → Add Node name→ Check Permanent Agent → Press Ok
- Add remote root directory to /Jenkins (We will be creating this directory in the slave node in a while).
- Select the Launch method: Launch agent via Java web start → Click Save. If the option is not showing, you need to add TCP port in Jenkins.
Manage Jenkins > Configure Global Security > TCP port for JNLP agents. Add a static port. (Enable the port in your firewall)
- You can see the newly created agent in the disconnected state
- Click on the node to see the start method
Connecting Master and Slave in Jenkins
Firstly, create a working directory /Jenkins in the slave. This will be the directory where Jenkins will put all the project files and must match with the remote root directory specified in Node in Jenkins(See image: Setup new node in Jenkins).
Open your mac terminal and hit command
cd / mkdir Jenkins sudo chmod 777 Jenkins open .
In the terminal you are doing the following:
- Navigate to the root directory
- Create a folder named Jenkins
- Give read-write permission to all users in Jenkins
- Check if you have successfully created Jenkins Directory
The final moment of the article, get ready :)
- Open Jenkins
- Open the slave
- Press the Launch Button
- Install the jnlp agent.
OR
You can download the jar file. Save the jar file to a directory → Open terminal → Navigate to the directory and execute the following command from the terminal. http://JenkinsServerAddress/computer/nodename/slave-agent.jnlp -secret somevalue
After the node is successfully connected, you can see the status connected as below:
Congrats! You have just set up a slave node. But, there is still a problem. What happens to the connection when your Mac restarts? Obviously, the connection will break. So, you should add a mechanism to make the connection of Master, Slave automatically when the slave starts. One way to do it is by adding the Jnlp in Login Items.
Setup Slave to connect automatically on System Restart
In order to run automatically Jenkins on System start, we need to add the Jnlp agent in system start items. For that
- Go to System Preferences
- Go to Users and Groups
- Navigate to Login Items
- Add the Jnlp using the + button.
Bingo, Now restart the system. And the slave connects automatically with Jenkins using Java Web Start.
Creating Jobs to Run on Slave
- To create a Job. Tap on New Item → Free Style Project
- Then you will land into the screen like this
- Go to Build Triggers Section → Click the checkbox “Restrict where this project can be run” and add the name of the slave.
- Click Apply
Finally, when you run this project, it will run all the builds in the Slave Node. To check, go to the Jenkins Directory in the slave. There, you can see the project files.
Thanks for reading! See you soon with Complete series of CI/CD setup using Jenkins for iOS build :).