Jenkins Pipeline Tutorial | How to create pipeline project in Jenkins to run automation test

3 min read 2 hours ago
Published on Oct 11, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of creating a Jenkins pipeline project to run automated tests. Jenkins is a popular open-source automation server that enables continuous integration and continuous delivery (CI/CD). By the end of this tutorial, you'll have a functional pipeline that automates your testing workflow.

Step 1: Install Jenkins

  1. Download Jenkins:

    • Go to the Jenkins website and choose the appropriate installer for your operating system.
  2. Install Jenkins:

    • Follow the installation instructions specific to your OS. For Windows, run the installer, and for Linux, use the package manager.
  3. Start Jenkins:

    • Once installed, start the Jenkins service. Open your web browser and navigate to http://localhost:8080.
  4. Unlock Jenkins:

    • Retrieve the initial admin password from the specified location (e.g., C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword on Windows).
    • Enter the password to unlock Jenkins.
  5. Install Plugins:

    • Choose to install recommended plugins during the setup process.
  6. Create Admin User:

    • Follow the prompts to create your first admin user and complete the setup.

Step 2: Create a New Pipeline Project

  1. Access Dashboard:

    • From the Jenkins dashboard, click on “New Item”.
  2. Name Your Project:

    • Enter a name for your pipeline project.
  3. Select Pipeline:

    • Choose the “Pipeline” option and click “OK”.
  4. Configure Your Pipeline:

    • In the project configuration page, scroll down to the "Pipeline" section.
  5. Define Pipeline Script:

    • You can either write your pipeline script directly or use the pipeline syntax generator to create it.
    • To use the generator, click on “Pipeline Syntax” at the bottom of the configuration page.

Step 3: Generate Pipeline Script

  1. Use the Pipeline Syntax Generator:

    • Select the type of step you want to add (e.g., "git", "sh", etc.).
    • Fill out the required fields based on your project needs.
  2. Copy the Generated Script:

    • Once you've configured your step, click "Generate Pipeline Script".
    • Copy the generated script into your pipeline configuration.
  3. Example of a Simple Pipeline Script:

    pipeline {
        agent any 
        stages {
            stage('Build') {
                steps {
                    echo 'Building...'
                }
            }
            stage('Test') {
                steps {
                    echo 'Testing...'
                }
            }
            stage('Deploy') {
                steps {
                    echo 'Deploying...'
                }
            }
        }
    }
    

Step 4: Save and Run Your Pipeline

  1. Save Your Configuration:

    • Click “Save” at the bottom of the configuration page.
  2. Run the Pipeline:

    • On the project page, click “Build Now” to execute the pipeline.
  3. Check Build Status:

    • Monitor the pipeline execution in the build history. Click on the build number to view logs and results.

Conclusion

In this tutorial, you learned how to set up a Jenkins pipeline project and generate a script using Jenkins' built-in tools. You can now automate your testing processes effectively. As you become more familiar with Jenkins, consider exploring additional plugins and enhancing your pipeline with more complex workflows. For further learning, check out related resources on Git, Selenium, and Jenkins tutorials linked in the video description.