An extendable open source continuous integration server that enables you to keep a close eye on various tasks you are performing when deploying apps.
- Jenkins
- Version : 2.492.3
- License :MIT License
- OS :Windows All
- Publisher :Jenkins CI
Jenkins is a popular open-source automation server that is widely used for continuous integration and continuous delivery (CI/CD). It helps automate the building, testing, and deployment of software projects. Here’s a beginner-friendly guide on how to get started with Jenkins:
1. Installing Jenkins:
For Windows:
- Download Jenkins: Go to the Jenkins download page and download the Windows installer (typically a
.msifile). - Run the Installer: Follow the installation wizard to install Jenkins on your machine.
- Launch Jenkins: After installation, Jenkins should start automatically. You can access Jenkins in your browser by navigating to
http://localhost:8080.
For macOS:
- Use Homebrew to install Jenkins:
brew install jenkins-lts - After installation, you can start Jenkins with:
brew services start jenkins-lts - Open your browser and go to
http://localhost:8080to access the Jenkins dashboard.
For Linux:
- Debian/Ubuntu:
sudo apt update sudo apt install openjdk-11-jdk sudo apt install jenkins sudo systemctl start jenkins sudo systemctl enable jenkins - Access Jenkins in your browser by going to
http://localhost:8080.
2. Unlocking Jenkins for the First Time:
When you access Jenkins for the first time, it will prompt you for an unlock key:
- Find the Unlock Key: The key is located in the
secrets/initialAdminPasswordfile in your Jenkins home directory.- For example, on Windows, it might be at:
C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword
- For example, on Windows, it might be at:
- Copy the password from this file and paste it into the unlock prompt on your Jenkins setup page.
- After entering the password, click Continue to proceed with the setup.
3. Setting Up Jenkins (First-Time Setup):
After unlocking Jenkins, you’ll be prompted to install suggested plugins:
- Install Suggested Plugins: This is the easiest and most common option. It will install plugins for version control systems, build tools, etc.
- Alternatively, you can choose Select Plugins to Install if you have specific plugins in mind.
Jenkins will automatically install the required plugins and restart itself.
4. Creating an Admin User:
- After plugin installation, you’ll be asked to create an admin user. Provide a username, password, and email address for the user.
- Once done, click Save and Finish.
5. Accessing the Jenkins Dashboard:
After setup is complete, Jenkins will show you the Dashboard:
- The Jenkins Dashboard is where you can manage your builds, configure Jenkins, and install more plugins.
6. Creating Your First Jenkins Job (Project):
A Jenkins “Job” is essentially a task or project that Jenkins will execute. Let’s create a basic job to automate building a simple project.
Steps:
- Create a New Job:
- From the Jenkins dashboard, click on New Item in the left-hand menu.
- Enter a name for the job (e.g., “My First Job”), and select the type of project. For now, select Freestyle Project.
- Click OK to proceed.
- Configure Your Job:
- Source Code Management: If you’re using a Git repository, under the Source Code Management section, choose Git and provide the repository URL. You can also provide credentials if your repo is private.
- Build Triggers: You can configure Jenkins to trigger the build in various ways:
- Poll SCM: Jenkins will check the source code repository periodically to see if there are any changes.
- Build Periodically: Jenkins will run the build at specific intervals (e.g., every night at midnight).
- Build: Under the Build section, you can define the build steps, such as:
- Running a shell script or batch command.
- Compiling code, running tests, or packaging the project.
- Example: To run a basic shell command, you can use the Execute Shell build step and enter a command like
echo "Hello, Jenkins!".
- Save and Build:
- After configuring the job, click Save.
- You can now manually trigger the build by clicking Build Now in the job’s page.
- View Build History:
- Jenkins will show you the history of builds for your job. You can check the status of the builds (success or failure) and review the console output for each build.
7. Running Jenkins Builds Automatically (CI/CD):
Jenkins is often used for Continuous Integration and Continuous Delivery, meaning your builds and deployments happen automatically when code changes. To set this up:
- Integrate Jenkins with a Source Code Repository:
- You can connect Jenkins to GitHub, GitLab, Bitbucket, or any other version control system.
- For GitHub, Jenkins can be triggered automatically when changes are pushed to the repository.
- To achieve this, use the GitHub Plugin in Jenkins or set up Webhook triggers.
- Set Up Pipeline Jobs:
- Jenkins Pipelines are used to define a series of automated steps that should be executed in a sequence. You can define the pipeline using Jenkinsfile, which is a text file that contains the pipeline’s definition.
- In the New Item menu, select Pipeline instead of Freestyle Project to create a new pipeline job.
- Example pipeline script (Jenkinsfile):
pipeline { agent any stages { stage('Build') { steps { echo 'Building the project...' } } stage('Test') { steps { echo 'Running tests...' } } stage('Deploy') { steps { echo 'Deploying the project...' } } } } - This script defines three stages: Build, Test, and Deploy. You can add specific commands in each stage to automate the corresponding task.
8. Installing and Using Jenkins Plugins:
Jenkins has a wide variety of plugins that can extend its functionality. You can install plugins from the Manage Jenkins section:
- Go to Manage Jenkins → Manage Plugins.
- From the Available tab, you can search for and install plugins like:
- Git: For Git integration.
- Maven: For Maven-based projects.
- Docker: For Docker container integration.
- Slack: For sending build notifications to Slack.
- After installing a plugin, Jenkins will usually require a restart.
9. Monitoring Builds and Notifications:
- Jenkins can send build notifications through email, Slack, or other channels.
- To set up email notifications, go to Manage Jenkins → Configure System, and set up SMTP mail server settings.
- In your job configuration, you can add a Post-build Action to send email notifications based on the build outcome (success, failure, etc.).
10. Securing Jenkins:
Jenkins can be configured with security settings to control access:
- Go to Manage Jenkins → Configure Global Security.
- You can enable authentication and authorization, set up roles, and integrate with external systems like LDAP or Active Directory.
11. Scaling Jenkins:
As your Jenkins environment grows, you may want to scale Jenkins by adding Jenkins agents (slaves) to distribute workloads across multiple machines. This helps improve performance when running many jobs in parallel.
Conclusion:
Jenkins is a powerful tool for automating the build, test, and deployment process of your software projects. It supports various plugins, integrations, and a flexible pipeline system for managing complex CI/CD workflows.
By setting up Jenkins, you can streamline development, catch issues early, and ensure your software is always tested and deployed efficiently.
