In this exercise, you will learn how to set up a basic CI/CD pipeline using Jenkins. This will involve creating a simple project, configuring Jenkins, and running your first build.
Objectives
- Understand the basic components of a CI/CD pipeline.
- Set up Jenkins on your local machine or a cloud service.
- Create a simple Jenkins job to automate the build process.
- Run the pipeline and verify the results.
Prerequisites
- Basic understanding of CI/CD concepts.
- Jenkins installed on your local machine or access to a Jenkins server.
- A version control system (e.g., Git) installed and configured.
Step-by-Step Guide
Step 1: Install Jenkins
-
Download Jenkins:
- Visit the Jenkins download page and download the appropriate installer for your operating system.
-
Install Jenkins:
- Follow the installation instructions for your operating system. For example, on Windows, run the installer and follow the prompts. On macOS, you can use Homebrew:
brew install jenkins-lts
- Follow the installation instructions for your operating system. For example, on Windows, run the installer and follow the prompts. On macOS, you can use Homebrew:
-
Start Jenkins:
- After installation, start Jenkins. On Windows, this might be done automatically. On macOS, you can start Jenkins with:
brew services start jenkins-lts
- After installation, start Jenkins. On Windows, this might be done automatically. On macOS, you can start Jenkins with:
-
Access Jenkins:
- Open a web browser and navigate to
http://localhost:8080
. You should see the Jenkins setup screen.
- Open a web browser and navigate to
Step 2: Configure Jenkins
-
Unlock Jenkins:
- During the initial setup, Jenkins will ask for an unlock key. This key can be found in the
initialAdminPassword
file located in the Jenkins home directory. Copy the key and paste it into the setup screen.
- During the initial setup, Jenkins will ask for an unlock key. This key can be found in the
-
Install Suggested Plugins:
- Jenkins will prompt you to install plugins. Choose "Install suggested plugins" to get started quickly.
-
Create an Admin User:
- Create an admin user by providing a username, password, and email address.
-
Configure Jenkins URL:
- Set the Jenkins URL to
http://localhost:8080
or the appropriate URL if you are using a cloud service.
- Set the Jenkins URL to
Step 3: Create a Simple Jenkins Job
-
Create a New Job:
- From the Jenkins dashboard, click on "New Item."
- Enter a name for your job (e.g., "BasicPipeline") and select "Freestyle project." Click "OK."
-
Configure Source Code Management:
- In the job configuration screen, scroll down to the "Source Code Management" section.
- Select "Git" and enter the repository URL of your project. For example, you can use a sample repository:
https://github.com/your-username/sample-repo.git
- If your repository is private, provide the necessary credentials.
-
Add Build Steps:
- Scroll down to the "Build" section and click "Add build step."
- Select "Execute shell" (or "Execute Windows batch command" on Windows).
- Enter a simple build command. For example, if you are using a Node.js project, you might use:
npm install npm test
-
Save the Job:
- Click "Save" to save your job configuration.
Step 4: Run the Pipeline
-
Build the Job:
- From the job's main page, click "Build Now."
- Jenkins will start the build process. You can monitor the progress in the "Build History" section.
-
Verify the Results:
- Once the build is complete, click on the build number (e.g., "#1") in the "Build History" section.
- Click on "Console Output" to see the details of the build process.
- Verify that the build steps were executed successfully.
Common Mistakes and Tips
- Incorrect Repository URL: Ensure that the Git repository URL is correct and accessible.
- Missing Dependencies: Make sure all necessary dependencies (e.g., Node.js, npm) are installed on the Jenkins server.
- Permissions Issues: If using a private repository, ensure that Jenkins has the correct credentials to access it.
Conclusion
In this exercise, you set up a basic CI/CD pipeline using Jenkins. You learned how to install and configure Jenkins, create a simple job, and run a build. This foundational knowledge will help you as you progress to more advanced CI/CD practices.
Next, you will integrate automated tests into your pipeline to ensure code quality and reliability.
CI/CD Course: Continuous Integration and Deployment
Module 1: Introduction to CI/CD
Module 2: Continuous Integration (CI)
- Introduction to Continuous Integration
- Setting Up a CI Environment
- Build Automation
- Automated Testing
- Integration with Version Control
Module 3: Continuous Deployment (CD)
- Introduction to Continuous Deployment
- Deployment Automation
- Deployment Strategies
- Monitoring and Feedback
Module 4: Advanced CI/CD Practices
Module 5: Implementing CI/CD in Real Projects
Module 6: Tools and Technologies
Module 7: Practical Exercises
- Exercise 1: Setting Up a Basic Pipeline
- Exercise 2: Integrating Automated Tests
- Exercise 3: Deployment in a Production Environment
- Exercise 4: Monitoring and Feedback