Jenkins integration


Jenkins is an open-source automation server that simplifies the process of building, testing, and deploying software. It allows developers to automate repetitive tasks, enhancing productivity and ensuring consistent quality throughout the software delivery process. With its wide range of plugins, Jenkins can easily integrate with various tools and platforms, making it a popular choice for continuous integration and continuous delivery (CI/CD) pipelines.

Testing your website's speed after deployment is crucial for maintaining a good user experience and effective search engine optimization. Research indicates that even slight delays in page load times can lead to user dissatisfaction and lower conversion rates. By integrating PageVitals into your Jenkins pipeline, you can automatically evaluate your website's performance against essential metrics, such as load times and interactivity. This way, you can catch potential performance issues early, allowing you to make necessary adjustments before they affect your visitors.

Use PageVitals CLI in a Jenkins Pipeline

The simplest way to test your pages after a rollout is to use PageVitals CLI inside a Jenkins pipeline script. You can configure Jenkins to execute the CLI commands with environment variables or parameters provided by the pipeline.

Steps:

  1. Ensure Jenkins is set up to run Node.js

    Install Node.js on your Jenkins build agents, or ensure the Node.js plugin is installed so that Jenkins can run npm commands. Make sure @pagevitals/pagevitals-cli is installed globally or locally within your pipeline.

  2. Create a Jenkinsfile

    This pipeline script will run the CLI to trigger PageVitals tests. Learn more about Jenkinsfile.

    pipeline {
    agent any
    environment {
    PAGEVITALS_API_KEY = credentials('pagevitals-api-key') // Jenkins secret for API Key
    WEBSITE_ID = 'your_website_id'
    }
    stages {
    stage('Install Dependencies') {
    steps {
    sh 'npm install -g @pagevitals/pagevitals-cli'
    }
    }
    stage('Run PageVitals Tests') {
    steps {
    sh '''
    pagevitals --api-key $PAGEVITALS_API_KEY run-tests \
    --website-id $WEBSITE_ID \
    --pages "homepage,contact" \
    --description "Jenkins build #${env.BUILD_ID}"
    '''

    }
    }
    stage('Process Results') {
    steps {
    // Process and report results if needed
    echo 'Tests completed!'
    }
    }
    }
    }
  3. Configure Jenkins credentials:

Use Jenkins' credentials management to securely store the PageVitals API key and inject it into the pipeline. Replace pagevitals-api-key in the pipeline script with the name of the Jenkins credential containing the PageVitals API key.