Setting up Jenkins on EC2 Mac Instance

Vaibhav Srivastava
4 min readMay 12, 2021

Amazon Web Services and Apple have partnered to bring modern cloud-provisioning capabilities to the macOS platform. In this article we will go over installing Jenkins on EC2 Mac instance.

Jenkins is an open-source Continuous Integration server which helps you to perform a chain of actions and thus helps you to achieve the Continuous Integration.

In Continuous Integration after a code commit, the software is built and tested immediately. In large projects where there are a lot of developers, they commit code many times in a day. With Jenkins after every commit, code is built and tested and if all goes well then continuous deployment happens.

Jenkins is not the only tool in this field, there are a lot of Continuous Integration tools available in the market like Bamboo, TeamCity, CircleCI, Travis, etc. but Jenkins is one of the most popular CI Tool.

let’s get started now.

Log in to the AWS management console and from EC2 dashboard, create a new instance using the MacOS AMI

You can also use Dedicated Hosts to launch Amazon EC2 instances on physical servers that are dedicated for EC2 MAC. Dedicated Hosts give you additional visibility and control over how instances are placed on a physical server, and you can reliably use the same physical server over time. As a result, Dedicated Hosts enable you to use your existing server-bound software licenses like Windows Server and address corporate compliance and regulatory requirements.

Select this AMI and follow the steps like adding tags, configuring security groups, etc. hit Launch.

Once the EC2 MAC instance is up and running, next step, we will SSH to our instance and install Jenkins using Git bash.

Jenkins can be installed using the Homebrew package manager. Homebrew formula: jenkins-lts This is a package supported by a third party which may be not as frequently updated as packages supported by the Jenkins project directly.
command: brew install jenkins-lts

after the installation is completed, we will start Jenkins service

brew services start jenkins-lts

I got an error starting the service, so I re-ran the command using sudo

Once Jenkin’s service is started, next is just take the public IP of the Jenkins server instance which we created in AWS and hit it in the browser. Dang, looks like it is not accessible over the browser

After researching what could be wrong I found this related article https://stackoverflow.com/questions/26570128/jenkins-server-is-not-accessible-by-host-name-ip-address

I installed Jenkins via homebrew and wanted the web interface to be accessible over the network. By default, Jenkins is launched with the — httpListenAddress=127.0.0.1 option and is only accessible on the local machine.

I found the plist file that was used to launch Jenkins in ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist and changed the argument, but each time I ran brew services restart Jenkins my changes would be lost. It turns out that this file only exists at run time. The config file that is actually used is located at ~/usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist . If you change this file then restart Jenkins then your changes should take effect.

After starting the Jenkins service, browse to http://{ec2-machine-ipaddress}:8080 and follow the instructions to complete the installation.

Summary

In this article, we saw a little Introduction about CI and Jenkins (Jenkins is a self-contained, open-source automation server that can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software) and also saw how we can install it on AWS EC2 Mac instance and what are the different steps involved right from installing to setting up Jenkins.

Helpful commands:

  • Install the latest LTS version: brew install jenkins-lts
  • Install a specific LTS version: brew install jenkins-lts@YOUR_VERSION
  • Start the Jenkins service: brew services start jenkins-lts
  • Restart the Jenkins service: brew services restart jenkins-lts
  • Update the Jenkins version: brew upgrade jenkins-lts

--

--

Vaibhav Srivastava

Solutions Architect | AWS & Azure Certified | Hybrid & Multi-Cloud Exp. | Technophile