Integration with Tekton
Tekton is a cloud native (Kubernetes native) CI/CD solution allowing creation and management of the software builds by the means of Kubernetes resources.
Tekton Pipelines
When working with tests using Tekton, you need to create a Pipeline and Task for this pipeline.
We'll use simplified examples to show what needs to be created, provided, configured. We recommend running the pipeline on this example repository first, then adapting it to your specific requirements.
Tekton Task
In the configuration file of a Tekton task, you need to provide at least these 3 variables in env section for allurectl to be able uploading the test results:
ALLURE_ENDPOINTALLURE_TOKENALLURE_PROJECT_ID
The rest of the parameters in env section are required for the proper test run linking on Allure TestOps side.
You also need to provide a mandatory parameter ALLURE_JOB_RUN_ID for the integration to work properly.
Task definition file
- Create a task definition file in your working directory,
- Name it. We'll use allure-example-test-task.yaml as an example,
- Add with the following content.
Here we use an example of Java JUnit5 tests with Gradle as the Build tool; some values are specific to Gradle and Java.
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: allure-example-test
spec:
params:
- name: ALLURE_JOB_RUN_ID
type: string
- name: namespace
type: string
- name: pipelineName
type: string
- name: pipelineRunName
type: string
steps:
- name: test
image: gradle:jdk8
script: |
git clone https://github.com/eroshenkoam/allure-example.git && cd allure-example
wget -q -O /usr/bin/allurectl https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_amd64 && chmod +x /usr/bin/allurectl
allurectl watch -- ./gradlew clean test
env:
- name: "ALLURE_ENDPOINT"
value: "https://where.is.allure.testops"
- name: "ALLURE_TOKEN"
value: "653458f1-4e6d-4afe-8190-394361d21f27"
- name: "ALLURE_PROJECT_ID"
value: "1"
- name: "ALLURE_CI_TYPE"
value: "tekton"
- name: "ALLURE_LAUNCH_NAME"
value: "$(params.pipelineName) - $(params.pipelineRunName)"
- name: "ALLURE_JOB_URL"
value: "https://tekton.qameta.space/#/namespaces/$(params.namespace)/pipelines/$(params.pipelineName)"
- name: "ALLURE_JOB_UID"
value: "$(params.namespace)/$(params.pipelineName)"
- name: "ALLURE_JOB_NAME"
value: "$(params.pipelineName)"
- name: "ALLURE_JOB_RUN_ID"
value: "$(params.ALLURE_JOB_RUN_ID)"
- name: "ALLURE_JOB_RUN_URL"
value: "https://tekton.qameta.space/#/namespaces/$(params.namespace)/pipelineruns/$(params.pipelineRunName)"
- name: "ALLURE_JOB_RUN_UID"
value: "$(params.pipelineRunName)"
- name: "ALLURE_JOB_RUN_NAME"
value: "$(params.pipelineRunName)"
- name: "ALLURE_TESTPLAN_PATH"
value: "./testplan.json"
- name: "ALLURE_RESULTS"
value: "build/allure-results"
env section
In the env section you need to define the following variables
| Environment Variable | Value |
|---|---|
| ALLURE_ENDPOINT | is Allure TestOps URL with protocol [http://, https://]., Mandatory |
| ALLURE_TOKEN | API token that will be used by allurectl., Mandatory |
| ALLURE_PROJECT_ID | Allure TestOps project ID, to which test results must be sent., Mandatory |
| ALLURE_RESULTS | /path/to/allure-results/ Path depends on your settings made for Allure Framework integration. Required for allurectl. |
| ALLURE_CI_TYPE | Always = tekton, Mandatory |
| ALLURE_LAUNCH_NAME | Can be constructed from the environment of pipeline execution $(params.pipelineName) - $(params.pipelineRunName), Optional |
| ALLURE_JOB_URL | Builds link that will be rendered in Job in Allure TestOps, e.g. https://tekton.some.dn/#/namespaces/ $(params.namespace)/pipelines/ $(params.pipelineName), Optional |
| ALLURE_JOB_UID | Unique job identifier like. Used in Allure TestOps $(params.namespace)/$(params.pipelineName), Optional |
| ALLURE_JOB_NAME | Job name = Pipeline name, $(params.pipelineName), Optional |
| ALLURE_JOB_RUN_ID | Used for proper linking of pipeline execution to a launch $(params.ALLURE_JOB_RUN_ID), Mandatory |
| ALLURE_JOB_RUN_URL | URL of the pipeline execution https://tekton.some.dn/#/namespaces/ $(params.namespace)/pipelineruns/ $(params.pipelineRunName) |
| ALLURE_JOB_RUN_UID | Identifier of the pipeline execution $(params.pipelineRunName) |
| ALLURE_JOB_RUN_NAME | Name of the pipeline execution $(params.pipelineRunName) |
Register task in Tekton
When ready, apply the Task configuration to Tekton as follows.
kubectl apply -f allure-example-test-task.yaml
Learn more about Tekton Tasks in the official documentation.
Tekton Pipeline
Next step is to create a Tekton pipeline that will be using the task we've just created.
Create a file named allure-example-pipeline.yaml in your working directory with the following content.
Pipeline definition file
As you can see, we are passing ALLURE_JOB_RUN_ID down to the task.
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: allure-example
spec:
params:
- description: Allure Job Run ID
name: ALLURE_JOB_RUN_ID
type: string
default: ""
tasks:
- name: test
taskRef:
name: allure-example-test
params:
- name: ALLURE_JOB_RUN_ID
value: "$(params.ALLURE_JOB_RUN_ID)"
- name: pipelineName
value: "$(context.pipeline.name)"
- name: pipelineRunName
value: "$(context.pipelineRun.name)"
- name: namespace
value: "$(context.pipelineRun.namespace)"
When ready, apply the Pipeline configuration to Tekton.
kubectl apply -f allure-example-pipeline.yaml
Learn more about Tekton Pipelines in the official documentation.
Tekton Pipeline Run
- Open the Tekton Dashboard and navigate to the PipelineRuns section.
- Click the Create button and select your pipeline.
- At the bottom of the screen, click Create to start the pipeline run.
Learn more about Tekton PipelineRuns in the official documentation.