DEV Community

Khairun Nahar Nowrin
Khairun Nahar Nowrin

Posted on • Edited on

Install and setup Jenkins with Homebrew in MacOs and configure with Github

To install Jenkins on a MacOS system, you can follow these steps:

Image description

  • Open terminal. Before install Jenkins using homebrew you must have install Homebrew in your local machine.

To install Homebrew, Follow the instruction.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


- 
Once the installation is complete, run the following command to verify that Homebrew is installed and working correctly:
Enter fullscreen mode Exit fullscreen mode

brew doctor


- 
If there are any issues reported by the `brew doctor` command, follow the instructions provided to resolve them.

- 
To update Homebrew to the latest version, run the following command:
Enter fullscreen mode Exit fullscreen mode

brew update


- 
You can now use Homebrew to install and manage software packages on your MacOS system. For example, to install the wget package, you can run the following command:
Enter fullscreen mode Exit fullscreen mode

brew install wget


- 
After successfully install Homebrew , Run 
this commands to Install the latest LTS version: 
Enter fullscreen mode Exit fullscreen mode

brew install jenkins-lts


- 
If you want to Install a specific LTS version Run this command.

Enter fullscreen mode Exit fullscreen mode

brew install jenkins-lts@YOUR_VERSION


- 
Next things to do to start the Jenkins service and for that Run:
Enter fullscreen mode Exit fullscreen mode

brew services start jenkins-lts


- 
For restart the Jenkins service: 
Enter fullscreen mode Exit fullscreen mode

brew services restart jenkins-lts


- 
For update the Jenkins version Run:
Enter fullscreen mode Exit fullscreen mode

brew upgrade jenkins-lts


- 
After Run `brew services start jenkins-lts` it will successfully start Jenkins. Go to Chrome or any browser and type 'http://localhost:8080/login?from=%2F'. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yutvdnw4f47xjdmhaq0t.png)
Copy the file server. Open terminal and Run

Enter fullscreen mode Exit fullscreen mode

cat /Users/daraz/.jenkins/secrets/initialAdminPassword


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q4iwwzofzp0e9v6r59w.png)

Copy that output and paste in **Administration password**. and click on Continue button

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1mhhl3hig4isfgt0csz.png)

- 
After that select Install suggest plugging in Customized Jenkins Screen. Select it and it will install necessary plugin.

Enter fullscreen mode Exit fullscreen mode

Image description


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m35m5wqla8cbzprghc7n.png)

- 
After finished installation it will redirect into Admin User screen where you need to create credential by input user name, password, email and click on Save and continue. Set the default local host, again click Save and continue. Now you good to go for start jenkins.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ke0bn6vtvrzx84rby29s.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9p9xwsviowgd8hwp2eeg.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d0me5zvuwdi2rys1w46.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7m1mnr1l06irzyomkgwk.png)


**<u>How to add GitHub Credentials in Jenkins</u>**

To add Jenkins credentials using a username, follow these steps:

- 
In Jenkins, go to the "Credentials" page, which is located in the "Security" section of the Jenkins settings.

- 
Click the "Add Credentials" button to open the "Add Credentials" form.

- 
In the "Kind" dropdown, select the "Username and Password" option.

- 
In the "Username" field, enter the username that you want to use.

- 
In the "Password" field, enter the password associated with the username.

- 
In the "ID" field, enter a unique ID for the credentials. This ID will be used to reference the credentials in your Jenkins jobs.

- 
Click the "OK" button to save the credentials.

Now you can use the username and password in your Jenkins jobs by referencing the ID of the credentials that you just added. For example, you might use the credentials to authenticate with a remote server or to log in to a web application as part of a Jenkins build.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ch26jcvsb52bw63q6uv9.png)
2. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w5yzjfnniikt4rl9rhx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhy4erwo1tvt88sodj9n.png)

**<u>Create a freestyle in Jenkins</u>**
To create a freestyle project in Jenkins, follow these steps:

- 
In Jenkins, go to the "New Item" page and give your project a name.

- 
Select the "Freestyle project" option in the "Kind" dropdown and click the "OK" button.

- 
In the "General" section of the project configuration, you can specify the source code repository for the project and the branch that you want to build. For my project i set GIT from source code management. Set my Github repository URL. Set credential which i already create from manage credentials. Specifier my brunch as 'Main'. Click on Apply than click on Save.

- 
Then Go to  "Build" section, and click on build. It will build successfully
- 
Save the project configuration and build the project.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0r8hsb0tmf65d4f29ud.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5o44bl7k86fo51x5rbv7.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3s1va2a0n757ajvqpo7h.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qurs5dfvp2ttu911bhwe.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05a2krdf6xox6xvl7mtc.png)

<u>**Create Jenkins Pipeline Using Jenkinsfile in GitHub Project**</u>

To create a pipeline in Jenkins, follow these steps:

- 
In Jenkins, go to the "New Item" page and give your pipeline a name.

- 
Select the "Pipeline" option in the "Kind" dropdown and click the "OK" button.

- 
In the "Pipeline" section of the project configuration, select the "Pipeline script" option in the "Definition" dropdown.

- 
In the "Script" field, configure GITHUB project URL. And Set Pipeline script from SCM from Pipeline definition section.

- 
Select SCM as None to GIT. Again Set the repository URl, set credential, set brunch as main


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqd5z576zlzx1z6gevs9.png)

**<u>Set up Docker plugin in Jenkins</u>**

If you need to Run dockerfile in Jenkins it should throw a error called "Docker not found". To resolve this error you need to install Docker inside Jenkins.
For that follow those steps:

- 
Select Manage Jenkins in the menu on the left side of the Jenkins dashboard.

- 
Click Manage Plugins in the Manage Jenkins window.

- 
Select the Available tab in the Plugin Manager window.

- 
Type Docker in the search field, and select the box next to the Docker plugin that appears in the search results.

- 
Click the Download now and install after restart button.

- 
When all the necessary plugin components download, select the box at the bottom of the screen to restart Jenkins.

link - https://phoenixnap.com/kb/how-to-configure-docker-in-jenkins

**<u>Configure Docker Build Agent in Jenkins</u>**

- 
Select the Manage Nodes and Clouds item in the System Configuration section.

- 
Click Configure Clouds in the menu on the left side.

- 
Expand the Add a new cloud list and select Docker.

- 
Provide the name and URI for the Docker host in the relevant fields. Enable the host by selecting the box.

- 
Select the Expose DOCKER_HOST box.

- 
Click the Docker Agent templates button to open additional configuration options.

- 
Provide the label for identifying the host, and enable the agent by selecting the Enabled option.

- 
Name the Docker template and provide the path to the Docker image.

- 
Specify the home folder for the Jenkins user you created.

- 
Choose Connect with SSH from the list in the Connect method section.Additional SSH configuration options appear.

- 
Select Use configured SSH credentials in the SSH key section. Provide the credentials you set up for the image in the field that appears below.

- 
Select Non verifying Verification Strategy in the Host Key Verification Strategy section.

- 
Click Save when you finish configuring the host.

link - https://phoenixnap.com/kb/how-to-configure-docker-in-jenkins
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
khairunnaharnowrin profile image
Khairun Nahar Nowrin