Skip to content

Connecting to CI/CD

Overview

We recommend creating a new CI/CD pipeline to automatically run tecton plan and tecton apply upon changes to your Tecton feature repo.

Example

For example, in GitHub actions, you can add the following:

name: Tecton Feature Repo CI/CD

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      TECTON_API_KEY: ${{ secrets.TECTON_API_KEY }}
      API_SERVICE: https://<YOUR CLUSTER SUBDOMAIN>.tecton.ai/api
      FEATURE_REPO_DIR: ./feature_repo
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Set up Python 3.7.10
      uses: actions/setup-python@v2
      with:
        python-version: 3.7.10

    - name: Install pypandoc (for pyspark bug https://stackoverflow.com/questions/51500288/unable-to-install-pyspark)
      run: pip install pypandoc

    - name: Install the Tecton CLI
      run: pip install --no-cache-dir 'tecton[pyspark]'

    - name: Run tecton plan
      run: cd ${FEATURE_REPO_DIR} && tecton plan --no-safety-check

    - name: Run tecton apply
      if: ${{ github.event_name == 'push' }}
      run: cd ${FEATURE_REPO_DIR} && tecton apply --no-safety-check

You'll also need to run tecton api-key create --description cicd --is-admin to create your Tecton API key, and add it to GitHub secrets. Note that setting TECTON_API_KEY and API_SERVICE as environment variables avoids the need for an interactive tecton login. For other CI/CD systems, you'll want to modify the above to match the format of the system you use.

(Beta Feature) Validate Plan with JSON output

You can output a JSON version of a to-be-applied diff using the --json-out flag.

tecton plan --json-out <path>
This can be useful in a CI/CD pipeline to prevent applying unintended changes by running a custom script on the output.

Example json file output:

{
  "objectDiffs": [
    {
      "transitionType": "DELETE",
      "objectMetadata": {
        "name": "transaction_user_has_good_credit",
        "objectType": "FEATURE_VIEW",
        "owner": "john@doe.com",
        "description": "Whether the user had a good credit score (over 670) as of the time of a transaction."
      }
    },
    {
      "transitionType": "RECREATE",
      "objectMetadata": {
        "name": "continuous_feature_service",
        "objectType": "FEATURE_SERVICE",
        "owner": "john@doe.com",
        "description": "A FeatureService providing continuous features."
      }
    }
  ]
}
See Understanding the Plan doc to help understand the plan output.