Setting Up Integration with Test IT
Preparing Data from Test IT
Test IT is a test management platform (TMS). Integration with Test IT allows you to manage automated tests located in GitFlic repositories.
Prepare and save the following data from Test IT for integration setup:
- PrivateToken user token - access token for using the utility and rest-api
- ProjectID - UUID of the project containing tests
- ConfigurationID - UUID of the configuration for running automated tests
- BaseUrl - URL where Test IT is deployed
These will be needed later when working with Test IT CLI
Preparing Data from GitFlic
Prepare and save the following data from GitFlic for integration setup:
- Api-token user token - access token for using rest-api
Configuration in Test IT
In Test IT, create a webhook for the Run Automated Tests event to trigger pipelines in GitFlic. For the url, specify the REST-API request to start a pipeline.
To create a REST-API request, you need to call a specific endpoint with the following base:
api.gitflic.ru
for API work on gitflic.rulocalhost:8080/rest-api
for API work in self-hosted builds
Domain and port may differ when working with self-hosted solutions.
Example request:
POST
https://my.gitflic.site/rest-api/project/ownername/projectname/cicd/pipeline/start
In the webhook headers, specify 2 parameters:
Name | Value |
---|---|
Content-Type | application/json |
Authorization | token |
Where {token} is the api-token created during GitFlic data preparation
Specify the following data in the request body and save:
- Context Type: Send custom content
- Replace System Parameters: true
- Escape Parameters: false
- Request Body: as in example
{
"refName": "master",
"isTag": "false",
"variables": [
{
"key": "TEST_RUN_ID",
"value" : "$TEST_RUN_ID"
}
]
}
If needed, supplement the request body with other predefined (system) variables. The documentation provides a list of available variables
Configuration in GitFlic
Save all data obtained from Test IT in project settings as CI/CD variables
For convenience, variable names have the following values:
GitFlic Variable Name | Test IT Variable Value |
---|---|
URL | URL where Test IT is deployed |
TOKEN | Access token for utility and rest-api use |
CONF_ID | UUID of configuration for automated tests |
PROJECT_ID | UUID of project containing tests |
Docker Base Image (configuration example)
The integration requires a GitFlic agent with Docker type
The image for integration testing should include python and curl. Use the dockerfile below to create such an image:
# Base image, let's call it demo-python-image
FROM python:3.11-slim
# Install curl and other dependencies
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Set working directory
WORKDIR /app
# Copy requirements.txt (delete this line if not present)
COPY requirements.txt .
# Install Python dependencies
# RUN pip install -r requirements.txt
RUN pip install testit-cli
# Default command
CMD ["python", "--version"]
Run docker build -t demo-python-image .
in the directory with the dockerfile
to build the demo image.
Prepare an automated testing results report yourself. Any .xml report from Pytest execution will work. Upload this report to the project in the results directory.
Creating gitflic-ci.yaml and Debugging Process
Create gitflic-ci.yaml in the project and fill it with the example code below:
# This file is a template CI/CD pipeline configuration. It can be modified as needed.
#
# Learn more about syntax in the documentation:
# https://docs.gitflic.ru/cicd/gitflic-ci-yaml
image: demo-python-image
variables:
TEST_RUN_ID: "empty"
stages:
- debug
- build
- testing
- sending
# debug_job:
# stage: debug
# script:
# - echo "URL = $URL"
# - echo "TOKEN = $TOKEN"
# - echo "CONF_ID = $CONF_ID"
# - echo "PROJECT_ID = $PROJECT_ID"
# - echo "PIPELINE_ID = $CI_PIPELINE_IID"
# - echo "TEST_RUN_ID = $TEST_RUN_ID"
build:
stage: build
script:
- echo "Built project" > build.txt
artifacts:
paths: build.txt
make_test:
stage: testing
needs: [build]
script:
- echo "Here PyTest jobs"
send_results:
stage: sending
needs: [make_test]
script:
- |
if [ "$TEST_RUN_ID" = "empty" ]; then
testit testrun create --url $URL \
--token $TOKEN \
-pi $PROJECT_ID \
--testrun-name "Pipe $CI_PIPELINE_IID" \
--output id.txt
TEST_RUN_ID="$(cat id.txt)"
else
echo "TestRunId = $TEST_RUN_ID"
fi
- |
curl -sS -L --fail-with-body --location --request PUT ''"$URL"'api/v2/testRuns' \
--header 'Authorization: PrivateToken '"$TOKEN"'' \
--header 'Content-Type: application/json' \
--data '{
"id": "'"$TEST_RUN_ID"'",
"name": "Pipe '"$CI_PIPELINE_IID"'",
"description": "'"$GITFLIC_USER_LOGIN"'",
"launchSource": "",
"attachments": [],
"links": []
}'
- |
testit results upload \
--url $URL \
--configuration-id $CONF_ID \
--results results/test-results.xml \
--token $TOKEN \
--testrun-id $TEST_RUN_ID
- |
testit testrun complete --url $URL \
--token $TOKEN \
--testrun-id $TEST_RUN_ID
Run the pipeline to test the integration.
Automatic Translation!
This page was automatically translated. The text may contain inaccuracies