Jenkins¶
Jenkins is a continuous integration tool. It can fetch the code from version control system ,build the code ,test it and notify to the developer.Jenkins can do continuous delivery also.jenkins having so many plugins ,by using these plugins we can do any task in jenkins.jenkin is a open sources project. It is a java based web application server so we need to setup first java on the machine to run jenkins server.
Jenkins CI CD Automation¶
Jenkins 1st Pipeline¶
Setting up a freestyle pipeline in Jenkins to link your Git public repository and run the ls
command in a bash shell is a straightforward process. Here are the detailed steps:
Prerequisites:¶
- Jenkins installed and configured.
- A public Git repository (e.g., GitHub, GitLab, Bitbucket).
- Administrative access to your Jenkins instance.
Step 1: Install Required Plugins (if not already installed)¶
-
In your Jenkins dashboard, click on "Manage Jenkins" in the left sidebar.
-
Click on "Manage Plugins."
-
Go to the "Available" tab and search for and install the following plugins if they are not already installed:
- Git Plugin: For Git integration.
-
Build Timeout Plugin (optional but recommended): To set a time limit for the build.
-
After installing the plugins, Jenkins may ask you to restart. If so, follow the prompts to restart Jenkins.
Step 2: Create a New Freestyle Project¶
-
In your Jenkins dashboard, click on "New Item" in the left sidebar.
-
Enter a name for your project (e.g., "MyFreestylePipeline") and select "Freestyle project."
-
Click "OK" to create the project.
Step 3: Configure Source Code Management (Git)¶
-
In the project configuration page, scroll down to the "Source Code Management" section.
-
Select "Git."
-
In the "Repository URL" field, enter the URL of your public Git repository.
-
You can leave the "Branches to build" field empty to build the default branch (e.g.,
main
ormaster
). -
If your Git repository requires credentials, click the "Add" button next to "Credentials" and enter your Git credentials. If it's a public repository, you may not need credentials.
-
Click "Save" at the bottom of the page.
Step 4: Configure Build Actions (Run ls
Command)¶
-
Scroll down to the "Build" section in your project configuration.
-
Click the "Add build step" dropdown and select "Execute shell" (for running bash commands).
-
In the "Command" text area, enter the
ls
command or any other bash command you want to run, e.g.:
-
Optionally, you can add more build steps or post-build actions as needed.
-
Click "Save" at the bottom of the page.
Step 5: Build the Freestyle Pipeline¶
-
In your Jenkins dashboard, locate your newly created freestyle project ("MyFreestylePipeline" or whatever you named it).
-
Click on the project name.
-
In the project page, click "Build Now" to trigger a build.
-
Jenkins will clone your Git repository, execute the
ls
command, and display the build output in the console.
That's it! You've set up a freestyle pipeline in Jenkins that links to your public Git repository and runs the ls
command in a bash shell. You can further customize your pipeline with additional build steps, post-build actions, and integration with other tools as needed.
Jenkins Setup¶
#!/bin/bash
sudo apt update
sudo apt install openjdk-8-jdk -y
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y
#!/bin/bash
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 yum upgrade -y
# Add required dependencies for the jenkins package
sudo yum install fontconfig java-11-openjdk -y
sudo yum install jenkins -y
CICD Setup¶
You can find my Jenkins CICD pipeline jobs which are saved in an HTML format, please download and extract to see the jobs
To View My Jenkins CICD Jobs (Click here)