Gitlab CI Integration

This article will guide you on how you may integrate vREST NG with Gitlab Pipelines via vrest-ng-cli module.

Download configuration file

Please download the below file and rename it as .gitlab-ci.yml. And add this file in the root directory of your source code repository.

  1. If you are using NodeJS based project:

    Download Gitlab CI File (via NPM)

  2. If you are using other than NodeJS based project:

    Download Gitlab CI File (via direct download)

Explanation

The process contains the following major steps in order to integrate vrest-ng-cli module. The steps are written on the basis of Alpine Linux machine.

  1. Download and install vREST NG CLI binary:

    First download and install the vREST NG CLI module.

    Via NPM way

    ...
    # [Use this step] To define the vrest-ng-cli version to be downloaded
    variables:
      vrest_version: '1.0.3' #vrest-ng-cli version to be downloaded
    
    test:
      stage: test
      script:
        ...
        # download the vrest-ng-cli npm module
        - npm install -g vrest-ng-cli@$vrest_version
        ...
    ...
    

    Via Direct Download way

    ...
    # [Use this step] To define the vrest-ng-cli version to be downloaded
    variables:
      vrest_version: '1.0.3' #vrest-ng-cli version to be downloaded
      vrest_uversion: '1_0_3' #underscore variant of vrest-ng-cli version
      npm_config_cache: '$CI_PROJECT_DIR/.npm'
      VREST_CACHE_FOLDER: '$CI_PROJECT_DIR/cache/vrest'
    
    test:
      stage: test
      script:
        ...
        - apk update && apk add ca-certificates && update-ca-certificates && apk --no-cache add openssl wget
    
        # download the vrest-ng-cli binary if cache doesn't exist
        - if [ -f $VREST_CACHE_FOLDER/vrest-ng-cli ]; then echo "vrest ng cli binary already cached."; else mkdir -p $VREST_CACHE_FOLDER && wget -O $VREST_CACHE_FOLDER/vrest-ng-cli -q https://github.com/Optimizory/vrest-ng-cli/releases/download/v$vrest_version/vrest_ng_cli_alpine_$vrest_uversion; fi
    
        # make the downloadable binary as executable
        - chmod u+x $VREST_CACHE_FOLDER/vrest-ng-cli
        ...
    ...
    
  2. Execute vREST NG Tests

    To execute the vREST NG tests, use the following code. For detailed information on the vrest-ng-cli command line options, please follow this guide link.

    ...
    test:
      stage: test
      script:
        ...
        # Execute the vREST NG tests
        - vrest-ng-cli run --projectdir=./test/scenario-tests --logger=xunit
        ...
    ...
    

    Note: If vrest-ng-cli is not in path then provide the absolute file e.g. $VREST_CACHE_FOLDER/vrest-ng-cli

  3. Publish Test Results

    Finally publish the test results produced by xunit logger of vrest-ng-cli module. By default vrest-ng-cli module exports the report in the vrest_logs/logs.xml of the current working directory. So, we can use those generated reports to publish them in Gitlab CI Pipelines.

    ...
    # [Use this step] To publish test results to gitlab ci
    artifacts:
      when: always
      paths:
        - vrest_logs/logs.xml
      reports:
        junit: vrest_logs/logs.xml
    

Reporting

vrest-ng-cli module generates the following types of reports in Gitlab CI pipelines:

  1. Console Report
  2. Test Run Results