Jenkins Pipeline

If you are running using Jenkins, you might have to export few variables first because they vary based on which type of pipeline and which plugin you are using.

Pre-requisites:

  • Complete integration of your SCM with HyperTest. Refer individual guides for Github, Gitlab and Bitbucket Intergration for the same.

  • Trigger your pipeline on every PR event

  • Build and deploy your test application

  • Download Hypertest CLI

  • Start a new test run from CLI

The above flow will ensure that every time a new PR is raised, tests are automatically triggred in HyperTest.

Set Variables:

Although, we automatically pick these variables, but if they are not picked up, you can manually set them before starting a test run

HT_BASE_URL=<http://hypertest-vm-ip:dashboard-port>
CI=true
HT_COMMIT_HASH=<your commit hash>
HT_BRANCH=<your source branch name of the PR>
HT_API_TOKEN=<your api token from central dashboard (required only for k8s based HT Setup)> 
HT_PR=<PR number (this is required only for gitlab & bitbucket)>

## If you are using Github SCM, please provide below variables, refer Github Checks Intergrations page for details
GITHUB_CONFIG_REPO_URL=<github_url>
GITHUB_CONFIG_INSTALLATION_ID=<installation_id>

## If you are using Gitlab SCM, please provide below variables, refer Gitlab Integration page for details
GITLAB_CONFIG_BASE_URL=<Base domain or https://gitlab.com> ## This is just the base domain and not complete URL of yuour gitlab repo
GITLAB_CONFIG_PROJECT_ID=<Gitlab_project_id> ## Project ID of your gitlab Project
GITLAB_CONFIG_ACCESS_TOKEN=<User_Access_token> ## Gitlab Access Token of User which has access to Repo - Scope -api

## If you are using BitBucket SCM, please provide below variables, refer BitBucket Intergrations page for details
BITBUCKET_CONFIG_WORKSPACE=<bitbucket-workspace>
BITBUCKET_CONFIG_REPO_SLUG=<bitbucket repo name>
BITBUCKET_CONFIG_USER_NAME=<bitbucket user-name>
BITBUCKET_CONFIG_APP_PASSWORD=<bitbucket app-password>

Depending on from where Jenkins is picking up code and what plugin and type of pipeline you are using Jenkins might be using different variable to store these values.

Below we have list of variables where Jenkins mainly expose it

  1. Branch name: GIT_BRANCH/ BRANCH_NAME/ CHANGE_BRANCH

  2. Last commit: GIT_COMMIT

  3. PR number: CHANGE_ID/ ghprbPullId

Sample files for CI/CD

A sample CI file for Jenkins is available below:

Jenkinsfile
#!/usr/bin/env groovy

// This is a basic workflow to help you get started with Jenkins Pipeline

// This pipeline should ony be triggered when you raise a PR/make changes to it

pipeline {
    agent any
    
    // Setting a few env for HyperTest Cli
    environment {
       HT_BASE_URL='http://<hypertest-vm-ip>:<dashboard-port>'
       HT_COMMIT_HASH="${sh (returnStdout: true, script: 'echo ${GIT_COMMIT}').trim()}"
       HT_BRANCH="${sh (returnStdout: true, script: 'echo ${GIT_BRANCH}').trim()}"
       HT_API_TOKEN='<ht-api-token (this is only required for k8s based HT setup)>'
       HT_PR='<PR number(required only for gitlab and bitbucket)>'
       // If you are using Github SCM, please provide below variables, refer Github Checks Intergrations page for details
       GITHUB_CONFIG_REPO_URL=<github_url>
       GITHUB_CONFIG_INSTALLATION_ID=<installation_id>

       // If you are using Gitlab SCM, please provide below variables, refer Gitlab Integration page for details
       // GITLAB_CONFIG_BASE_URL=<Base domain or https://gitlab.com> ## This is just the base domain and not complete URL of yuour gitlab repo
       // GITLAB_CONFIG_PROJECT_ID=<Gitlab_project_id> ## Project ID of your gitlab Project
       // GITLAB_CONFIG_ACCESS_TOKEN=<User_Access_token> ## Gitlab Access Token of User which has access to Repo - Scope -api

       // If you are using BitBucket SCM, please provide below variables, refer BitBucket Intergrations page for details
       // BITBUCKET_CONFIG_WORKSPACE=<bitbucket-workspace>
       // BITBUCKET_CONFIG_REPO_SLUG=<bitbucket repo name>
       // BITBUCKET_CONFIG_USER_NAME=<bitbucket user-name>
       // BITBUCKET_CONFIG_APP_PASSWORD=<bitbucket app-password>
    }

    stages {
    
        // Steps to build your application
        stage('Build') { 
            steps {
                sh 'echo "steps to build"'
            }
        }
      
        // Steps to deploy your application
        stage('Deploy') {
            steps {
                sh 'echo "steps to deploy"'
            }
        }
        
          // Steps to test your application
        stage('Deploy') {
            steps {
                sh 'echo "steps to test"'
            }
        }
        
        // Steps to start a new test run
        stage('Start new test run') {
        
            steps { 
                sh 'echo "This job downloads HyperTest Cli and start a new test"'               
                sh 'printenv|sort'
                sh 'wget -O ht-cli.tar.xz https://hypertest-binaries-1.s3.ap-south-1.amazonaws.com/ht-cli/ht-cli-latest.tar.xz'
                sh 'tar xvf ht-cli.tar.xz'
                sh './hypertest can-run-test'
                sh './hypertest start-new-test'
            }
        }
    }
}

Getting Started:

1. Download HyperTest CLI

wget -O ht-cli.tar.xz https://hypertest-binaries-1.s3.ap-south-1.amazonaws.com/ht-cli/ht-cli-latest.tar.xz -nv'
tar xvf ht-cli.tar.xz

2. Check if HyperTest can start a test

./hypertest can-run-test

3. Start new test run

./hypertest start-new-test

Last updated