In this section, we will guide you through creating your first Jenkins job. This will help you understand the basic workflow of Jenkins and how to set up and run a simple job.
Objectives
- Create a new Jenkins job.
- Configure the job to perform a basic task.
- Run the job and review the results.
Step-by-Step Guide
- Accessing Jenkins Dashboard
- Open your web browser and navigate to your Jenkins instance (e.g.,
http://localhost:8080
). - Log in with your credentials.
- Creating a New Job
- On the Jenkins dashboard, click on the "New Item" link on the left-hand side.
- Enter a name for your job (e.g.,
FirstJob
). - Select "Freestyle project" and click "OK".
- Configuring the Job
- You will be redirected to the job configuration page.
- In the "General" section, you can add a description for your job (optional).
Source Code Management
- For this example, we will not use any source code management. Leave this section as it is.
Build Triggers
- You can set up triggers to automatically start the job. For now, we will manually trigger the job, so leave this section as it is.
Build Environment
- Leave this section as it is for now.
Build
- Click on "Add build step".
- Select "Execute shell" (for Unix/Linux) or "Execute Windows batch command" (for Windows).
- In the command box, enter a simple command. For example:
- Unix/Linux:
echo "Hello, Jenkins!"
- Windows:
echo Hello, Jenkins!
- Unix/Linux:
Post-build Actions
- Leave this section as it is for now.
- Click "Save" to save your job configuration.
- Running the Job
- You will be redirected to the job's main page.
- Click on "Build Now" on the left-hand side to start the job.
- Reviewing the Results
- After the job runs, you will see a new build entry under the "Build History" section on the left-hand side.
- Click on the build number (e.g.,
#1
) to view the build details. - Click on "Console Output" to see the output of the job. You should see the message
Hello, Jenkins!
.
Practical Exercise
Exercise 1: Create and Run a Simple Jenkins Job
- Create a new Jenkins job named
MyFirstJob
. - Configure the job to print
Welcome to Jenkins!
using the appropriate shell or batch command. - Run the job and verify the output.
Solution
- Create a new job named
MyFirstJob
as described in the steps above. - In the build step, enter the following command:
- Unix/Linux:
echo "Welcome to Jenkins!"
- Windows:
echo Welcome to Jenkins!
- Unix/Linux:
- Save the job and run it. Check the console output to verify the message
Welcome to Jenkins!
.
Common Mistakes and Tips
- Mistake: Forgetting to save the job configuration.
- Tip: Always click "Save" after configuring your job to ensure your settings are applied.
- Mistake: Incorrect command syntax for the operating system.
- Tip: Ensure you use the correct command syntax for your operating system (Unix/Linux vs. Windows).
Conclusion
Congratulations! You have successfully created and run your first Jenkins job. This basic understanding of job creation and execution will serve as a foundation for more complex tasks in Jenkins. In the next module, we will explore the Jenkins dashboard in more detail and learn how to create and run more advanced jobs.
Jenkins: From Beginner to Advanced
Module 1: Introduction to Jenkins
Module 2: Jenkins Basics
- Jenkins Dashboard Overview
- Creating and Running Jobs
- Understanding Jenkins Pipelines
- Using Jenkins Plugins
Module 3: Jenkins Pipelines
Module 4: Advanced Jenkins Pipelines
- Pipeline Stages and Steps
- Parallel Execution in Pipelines
- Using Environment Variables
- Pipeline Best Practices
Module 5: Jenkins Administration
Module 6: Integrating Jenkins
- Integrating with Version Control Systems
- Integrating with Build Tools
- Integrating with Testing Tools
- Integrating with Deployment Tools