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

  1. Accessing Jenkins Dashboard

  1. Open your web browser and navigate to your Jenkins instance (e.g., http://localhost:8080).
  2. Log in with your credentials.

  1. Creating a New Job

  1. On the Jenkins dashboard, click on the "New Item" link on the left-hand side.
  2. Enter a name for your job (e.g., FirstJob).
  3. Select "Freestyle project" and click "OK".

  1. Configuring the Job

  1. You will be redirected to the job configuration page.
  2. 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

  1. Click on "Add build step".
  2. Select "Execute shell" (for Unix/Linux) or "Execute Windows batch command" (for Windows).
  3. In the command box, enter a simple command. For example:
    • Unix/Linux:
      echo "Hello, Jenkins!"
      
    • Windows:
      echo Hello, Jenkins!
      

Post-build Actions

  • Leave this section as it is for now.
  1. Click "Save" to save your job configuration.

  1. Running the Job

  1. You will be redirected to the job's main page.
  2. Click on "Build Now" on the left-hand side to start the job.

  1. Reviewing the Results

  1. After the job runs, you will see a new build entry under the "Build History" section on the left-hand side.
  2. Click on the build number (e.g., #1) to view the build details.
  3. 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

  1. Create a new Jenkins job named MyFirstJob.
  2. Configure the job to print Welcome to Jenkins! using the appropriate shell or batch command.
  3. Run the job and verify the output.

Solution

  1. Create a new job named MyFirstJob as described in the steps above.
  2. In the build step, enter the following command:
    • Unix/Linux:
      echo "Welcome to Jenkins!"
      
    • Windows:
      echo Welcome to Jenkins!
      
  3. 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.

© Copyright 2024. All rights reserved