Gitlab Integration

Setup guide for Integrating Gitlab with HyperTest.

Pre-requisites

  1. Your repositories are hosted on Gitlab

  2. Your Gitlab user account should have your repository

  3. HyperTest CLI is called from your CI tool on pull request events. Refer CI Integration

Sample file

A sample CI file for gitab CI/CD runner can be found below

.gitlab-ci.yml
## This is a basic workflow to help you get started with Gitlab CI/CD

stages:
  - build
  - test
  - deploy
  - hypertest


variables:
  HT_BASE_URL: $HT_BASE_URL
  HT_API_TOKEN: '<your api token>' ## required only for K8s based HT setup, not for linux based HT Setup
  ## Read below documentation for these Variables, if you are passing variables here you don't need to do Step 3
  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: '<Access_token>' ## Gitlab Access Token of User which has access to Repo - Scope -api

## Job to build application
build-app:
  stage: build
  only:
    - merge_requests
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"
    - echo "Add other actions to build"


## Job to deploy application to test environment
deploy-app:
  stage: deploy
  only:
    - merge_requests
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch to test environment"
    - echo "Add other actions to deploy"
    
    
## Job to test application
test-app:
  stage: test
  only:
    - merge_requests
  script:
    - echo "This job tests something"
    - echo "Add other actions to test"
    
  
## Job to download HyperTest CLI and then start a new test from CLI   
hypertest-start-test:
  stage: hypertest
  only:
    - merge_requests
  script:
    - echo "This job downloads HyperTest Cli and start a new test"
    - wget -O ht-cli.tar.xz https://hypertest-binaries-1.s3.ap-south-1.amazonaws.com/ht-cli/ht-cli-latest.tar.xz 
    - tar xvf ht-cli.tar.xz
    - printenv|sort
    - ./hypertest can-run-test
    - ./hypertest start-new-test

Steps to integrate Gitlab

Step 1: Create a personal access token

HyperTest will add comments on the merge request discussions. We recommend you create a new user in gitlab and add to your repo for this. You can however use an existing user as well.

Steps to create a personal access token

  1. Required scopes for access token creation: api

  2. create an access token with a large expiry (like 10 years)

Step 2: Get project ID

Step 3: Update HyperTest Configuration

To publish reports on your CI, we need to provide above ID's etc to HyperTest. You can either add it is a configuration in HyperTest Dashboard's Service Configuration or pass it as environment variable in your CI, while starting a test.

If you have already passed the Gitlab Configurations such as base url, token etc in your CI file, you don't need to do this Step 3.

Below is example for both

a. HyperTest's Dashboard Configuration

1.Set GITLAB_BASE _URL as your base domain (if self hosted) or as https://gitlab.com (if using GitLab cloud version)

2.Add both the Project ID and Base URL in HyperTest's configuration. This can be done by navigating to the Settings page in HyperTest Dashboard. Click on Service Configuration and paste the project ID and base URL.

GITLAB_CONFIG:
  GITLAB_BASE_URL: <Base domain or https://gitlab.com>
  GITLAB_PROJECT_ID: <Gitlab_project_id>
  GITLAB_ACCESS_TOKEN: <Access_token>

Click on "Update" and you have successfully integrated Gitlab with HyperTest.

b. Add the below enviornment variables in your CI pipeline

See details in gitlab CI file above

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: '<Access_token>' ## Gitlab Access Token of User which has access to Repo - Scope -api

Now every time your CI(Gitlab or other CI tools) triggers a test through HyperTest CLI, HyperTest will add Check reports to your merge request.

By default, checks will be in a failed state in order for you to read the HyperTest Report.

Last updated