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
- Login to your EC2 instance
- 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
- Once the jenkins is started, it will listen on port
8080
. - You can access the Jenkins UI using
http://PUBLIP-IP:8080
- Follow through the instructions on configuring Jenkins. To get the Admin password issue below command,
shell
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- On next screen, select "Install suggested plugins"
- Configure the Admin user by providing information on the form
- For instance configuration, click "Not now"
- 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
- This script defines a Jenkins pipeline with four stages: Checkout, Build, Test, and Package.
- Each stage uses specific commands to perform its tasks.
- The script uses the node keyword to specify a Jenkins slave where the build will be executed.
- The git command checks out the code from a Git repository.
- The sh command executes shell commands like building with Maven and running a package script.