Integrating automation framework with Jenkins for continuous integration and continuous deployment (CI/CD)

Integrating automation framework with Jenkins for continuous integration and continuous deployment (CI/CD)

Integrating your codeceptjs automation framework with Jenkins for continuous integration and continuous deployment (CI/CD) involves several steps. These include setting up Jenkins, configuring your project, creating a Jenkinsfile for your pipeline, and ensuring that Jenkins can run your tests and generate reports. Here's a step-by-step guide to achieve this:

1. Setting Up Jenkins

Install Jenkins:

  • Download and install Jenkins from the official Jenkins website.
  • Follow the installation instructions specific to your operating system.

Start Jenkins:

  • Run Jenkins and open it in a web browser (usually accessible at https://localhost:8080).

Install Required Plugins:

  • Go to Manage Jenkins > Manage Plugins.
  • Install the following plugins:

Pipeline

NodeJS

Allure Jenkins Plugin (for Allure reports)

2. Configuring Your Project

Create a New Jenkins Job:

  • Go to Jenkins dashboard.
  • Click on New Item.
  • Choose Pipeline and give your job a name.
  • Click OK.

Configure NodeJS:

  • Go to Manage Jenkins > Global Tool Configuration.
  • Under NodeJS, click on Add NodeJS and configure it (e.g., name it NodeJS 14.x).

3. Creating a Jenkinsfile

Create a Jenkinsfile in the root of your project directory. This file will define the stages and steps for your Jenkins pipeline. Here is an example Jenkinsfile:

pipeline {
    agent any

    environment {
        NODEJS_HOME = tool name: 'NodeJS 14.x', type: 'NodeJSInstallation'
        PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"
    }

    stages {
        stage('Install Dependencies') {
            steps {
                script {
                    // Clean and install dependencies
                    sh 'npm install'
                }
            }
        }

        stage('Run Tests') {
            steps {
                script {
                    // Run the tests
                    sh 'npx codeceptjs run'
                }
            }
        }

        stage('Generate Allure Report') {
            steps {
                script {
                    // Generate the Allure report
                    sh 'allure generate ./output/allure-results --clean'
                }
            }
        }

        stage('Publish Allure Report') {
            steps {
                allure([
                    includeProperties: false,
                    jdk: '',
                    properties: [],
                    reportBuildPolicy: 'ALWAYS',
                    results: [[path: 'output/allure-results']]
                ])
            }
        }
    }

    post {
        always {
            // Clean up workspace
            cleanWs()
        }
    }
}
        

4. Configuring Jenkins Job

1. Pipeline Script from SCM:

  • In your Jenkins job configuration, select Pipeline and then Pipeline script from SCM.
  • Choose Git as the SCM and provide the repository URL (e.g., https://github.com/yourusername/yourrepository.git).
  • Specify the branch you want to build (e.g., main or master).
  • Set the path to your Jenkinsfile within the repository (e.g., Jenkinsfile).

2. Save and Build:

  • Save the configuration and click Build Now to run your pipeline.


5. Running the Pipeline

1. Start a Build:

  • Go to your Jenkins job and click Build Now.
  • Monitor the build progress in the Console Output to ensure that the steps are executed correctly.

2. View Allure Report:

  • After the build completes, go to the build details.
  • Click on Allure Report to view the generated report.


Additional Considerations

  • Jenkins Slave Nodes: If your tests need to run on specific environments (e.g., different OS or browsers), you can configure Jenkins slave nodes to run the tests in those environments.
  • Environment Variables: Use Jenkins environment variables to manage different configurations or credentials securely.
  • Notifications: Configure email or other notification methods to alert you when builds fail or succeed.

By following these steps, you can set up a Jenkins CI/CD pipeline for your automation framework, allowing you to run your tests and generate reports automatically with each code change.


要查看或添加评论,请登录

Keshab Fouzdar的更多文章

社区洞察

其他会员也浏览了