Skip to content

Jenkins

Jenkins is a popular open-source automation server used for continuous integration and continuous delivery (CI/CD) of software. It automates the building, testing, and deployment of software projects, enabling developers to quickly and reliably release new updates.

Key Features

  • Flexibility: Supports diverse plugins for various tasks like code analysis, deployments, notifications, and integrations with other tools.
  • Open Source: Free and open-source software with a large community for support and contribution.
  • Easy Configuration: User-friendly interface for configuring builds, pipelines, and jobs.
  • Extensive Plugin Ecosystem: Wide array of plugins available for extending functionalities and integrating with different platforms and services.
  • Scalability: Can handle complex and large-scale projects by distributing builds and using slave nodes.

Installing Jenkins

  1. Login to your EC2 instance
  2. Run the following commands to install and start jenkins
shell
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo dnf install java-11-amazon-corretto-devel
sudo yum install jenkins --nogpgcheck
sudo service jenkins start
  1. Once the jenkins is started, it will listen on port 8080.
  2. You can access the Jenkins UI using http://PUBLIP-IP:8080
  3. Follow through the instructions on configuring Jenkins. To get the Admin password issue below command,
shell
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  1. On next screen, select "Install suggested plugins"
  2. Configure the Admin user by providing information on the form
  3. For instance configuration, click "Not now"
  4. Jenkins is now up and running

Sample Jenkins Script

groovy
node {
  // Stage for checking out code from Git repository
  stage('Checkout') {
    git url: 'https://github.com/your-organization/your-project.git'
  }
  // Stage for building the project
  stage('Build') {
    sh 'mvn clean install'
  }
  // Stage for running unit tests
  stage('Test') {
    sh 'mvn test'
  }
  // Stage for deploying the application
  stage('Package') {
    sh 'mvn package'
  }
}

Explanation

  1. This script defines a Jenkins pipeline with four stages: Checkout, Build, Test, and Package.
  2. Each stage uses specific commands to perform its tasks.
  3. The script uses the node keyword to specify a Jenkins slave where the build will be executed.
  4. The git command checks out the code from a Git repository.
  5. The sh command executes shell commands like building with Maven and running a package script.

Released under the MIT License. Some of the contents are generated using Gen AI