1. Help Center
  2. Testcontainers Cloud for CI

How to use Testcontainers Cloud with Tekton

Make sure TC_CLOUD_TOKEN is set to your corresponding token value, download the agent and start it before running the tests.

To use Testcontainers Cloud with Tekton you need to set TC_CLOUD_TOKEN to your corresponding service account token. You can generate the token in the Testcontainers Cloud dashboard. Then add the token to your pipeline by creating a secret and using it as a  variable in your pipeline task. 

For example, you can define a secret in a separate secret.yaml file like in the following example:

apiVersion: v1
kind: Secret
  name: tcc-token

Next you need to configure your Tekton pipeline to install and use Testcontainers Cloud agent prior running the tests. For that you can use the Testcontainers Cloud agent installation script.

Here's a sample configuration for a Tekton task task.build.yaml which bind the above secret to the TC_CLOUD_TOKEN environment variable, and runs the script that installs and starts Testcontainers Cloud agent, and then calls to the Maven test command. 

apiVersion: tekton.dev/v1beta1
kind: Task
  name: build-java-maven
    - name: source
    - name: maven-build
      image: amazoncorretto:17.0.5-al2
        - name: TC_CLOUD_TOKEN
              name: tcc-token
              key: token
      script: |
        set -e
        cd "$(workspaces.source.path)"
        sh -c "$(curl -fsSL https://get.testcontainers.cloud/bash)"
      ./mvnw test

This is a flexible approach you can use to run Testcontainers Cloud in Tekton with the tests in other languages by swapping the mvn command for the corresponding build tool call.