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/reponame/allure-example-ae.git && cd allure-example-ae
wget -q -O ./allurectl https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_amd64 && chmod +x ./allurectl
./allurectl watch -- ./gradlew clean test
securityContext:
runAsNonRoot: true
runAsUser: 1000
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
env:
- name: "ALLURE_ENDPOINT"
value: "https://where.is.allure.testops"
- name: "ALLURE_TOKEN"
value: "653458f1-1111-2222-4444-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://tektondomain.name/#/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://tektondomain.name/#/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://tektondomain.name/#/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://tektondomain.name/#/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
To create a Tekton pipeline run you need to create the definition of such run
- Create
allure-example-pipelinerun.yaml - Add the following content.
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: allure-example-run-
namespace: tekton-pipelines
spec:
pipelineRef:
name: allure-example
params:
- name: ALLURE_JOB_RUN_ID
value: ""
serviceAccountName: default
podTemplate:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
- Send for the execution
kubectl create -f allure-example-pipelinerun.yaml
Checking running pipeline execution
To check the statuses of pipeline runs, execute this command.
kubectl get pipelineruns -n tekton-pipelines
Cleaning the history of pipeline runs
To delete historical pipeline executions run this command.
kubectl delete pipelineruns --all -n tekton-pipelines
Learn more about Tekton PipelineRuns in the official documentation.
Triggering Tekton pipelines from Allure TestOps
This is the second direction of the bi-directional integration with Tekton.
Prerequisites
To be able to trigger Tekton pipelines from Allure TestOps you need.
- to have Tekton dashboards deployed
- To have all mandatory and optional environment variables added to the task.
- Having #2 in place, you need to execute pipeline with all environment variables at least once, so on Allure TestOps a new Job will be created.
Adding Tekton integration
To do so, we need to have an integration with CI/CD server (in our case it's Tekton).
Generally, for each and any integration type on Allure TestOps side we have to perform 2 steps:
- An instance administrator creates an integration globally:
- Provides type.
- Name.
- Endpoint(s) for the integration.
- A project owner configures the integration on a project level
- Provides credentials for the authentication of API calls
- Provides additional configuration parameters if such action can be applied to the integration of certain type.
The integration created globally (on the instance level) is used in all projects that require such integration type, i.e. if we have created a global integration for Tekton, then on the instance level we only do it once.
Add Tekton integration :: Global settings
- Log in to Allure TestOps using an administrator account.
- Go to Administration → Integrations.
- Click + Add integration in the top right corner of the page.
- In the dialog that appears, select Tekton.
- Fill in the fields:
- Name — a name to help you recognise Tekton instance (e.g. simply, "tektondomain.name").
- Endpoint — the base URL of Tekton https://tektondomain.name.
- Click Add integration.
Add Tekton integration :: Project level
- In Allure TestOps, open your project.
- Go to Settings → Integrations.
- Under Available integrations, find the Tekton integration and click Add integration next to it.
- Click Test connection. If the token is correct, a "Connection established" message will appear within a few seconds.
- Click Add integration to save the settings.
Using Tekton dashboard for triggering pipelines does not require any authentication, leave the token field blank.
Update Job
Now we need to update the Job created for Tekton pipeline execution.
- Go to Allure TestOps project.
- Go to Jobs section.
- Select the Job configuration menu
⋯and click Configure. - Keep the name as it is
- In Build server select the integration with Tekton we created in previous steps.
- Parameter Job can be used to run tests must be checked.
- Save the applied configuration by hitting Submit
If you are receiving error related to incorrect credentials, then you need to troubleshoot your deployment or Tekton, correctness of the domain name etc.
After Job was updated, you can run automated tests and run whole job from Allure TestOps UI.