Exploring Jenkins

Exploring Jenkins
ibnu gunawan prayogo

Ibnu Gunawan P

Tue, 22 2021, 11:39:00 pm

Table Of Content

Exploring Jenkins

Jenkins is a powerful open-source automation server, crafted using the versatile Java programming language. One of its primary purposes is to facilitate Continuous Integration and Continuous Delivery, commonly referred to as CI/CD processes. In simpler terms, Jenkins is your trusty sidekick for automating tasks such as testing, building, and deployment.

# Installing Jenkins

For the installation process, I've prepared a nifty bash script that makes setting up Jenkins a breeze. Just follow these simple steps:

$ git clone https://github.com/notme1001/jenkins-run.git && cd jenkins-run
$ ./test.sh
+++++++++++++++++++++++++++++++++++inu++++++++++++++++++++++++++++++++++++++++++++
      __               __    __                                              
     |__| ____   ____ |  | _|__| ____   ______         _______ __ __  ____   
     |  |/ __ \ /    \|  |/ /  |/    \ /  ___/  ______ \_  __ \  |  \/    \  
     |  \  ___/|   |  \    <|  |   |  \___ \   /_____/  |  | \/  |  /   |  \ 
 /\__|  |\___  >___|  /__|_ \__|___|  /____  >          |__|  |____/|___|  / 
 \______|    \/     \/     \/       \/     \/                            \/  
=============================Jenkins-Installer====================================
Simple Install Jenkins With one command, Select your Linux distribution for installation:
 Date: Tuesday, March 23, 2021, 05:49:33 AM  WIB
 1 - CentOS 7
 2 - Ubuntu or Debian
 3 - Example Jenkinsfile
Enter your selection:

Choose the Linux distribution used on your server or locally. Once the installation is complete, you can access Jenkins by opening the Jenkins URL with the default port, which is 8080. http://ip-server:8080.

Configuring Jenkins

  • To unlock Jenkins, run the command below, and make sure to copy the password key to access Jenkins.
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

/assets/articles/1616502908-2021-03-23-193428984x542scrot.png

  • Continue by selecting "Install suggested plugins."

/assets/articles/1616503198-2021-03-23-1939261456x950scrot.png

  • Set your username and password.

/assets/articles/1616503326-2021-03-23-1941191294x860scrot.png

  • Configure the URL address for Jenkins.

/assets/articles/1616503751-group-2.png

# Usage

Integrating Jenkins with GitHub allows automatic deployment when pushing to a specific branch.

  • Create a new job, provide a job name, and select "Pipeline."

/assets/articles/1616503956-2021-03-23-1951361796x891scrot.png

  • In the General tab, check "GitHub Project" and enter the GitHub repository URL you intend to use.

/assets/articles/1616504257-2021-03-23-1956271486x442scrot.png

  • In the Build Triggers tab, check "GitHub hook trigger for GITScm polling."

/assets/articles/1616504412-2021-03-23-1958511484x313scrot.png

  • In the Pipeline tab, configure it as shown below, and save the Pipeline configuration.

/assets/articles/pipeline.png

Explanation of Pipeline Configuration

  1. We set the environment variable to include the path to Docker Compose, which is useful if you're using Docker for deployment. If not, you can skip this part.
  2. The "stages" section defines the steps Jenkins will take. Here, I've created three stages: "Build," "Test," and "Deploy," each with corresponding actions.
  3. The "sh" command is used to execute Linux commands. In this example, it lists the contents of the workspace directory.
  • At this point, you can test the build process in Jenkins.

/assets/articles/build.png

  • Here's the result of the build process in Jenkins.

/assets/articles/testBuild.png

  • Witness the integration of Jenkins and GitHub: Whenever you push to the repository, Jenkins automatically initiates the build by pulling the repository and running the Jenkinsfile.

/assets/articles/1616506592-2021-03-23-203622355x155scrot.png

/assets/articles/last.png

# Author's Note

Easy, right?

In reality, Jenkins can do more than what I've described above. For instance, it can send messages after the build process using a Telegram bot or email. But for now, that's all I can provide. Hopefully, you find it useful.