Skip to main content

Example: Using envsubst to populate CircleCI Project IDs for Release Agent

Introduction:

To enable your deployment to show up on the deploys UI in the CircleCI web app, an annotation (circleci.com/project-id) is required on your Kubernetes Deployment or Argo Rollout specifying the CircleCI project ID.

This article provides an example of how to populate this value from the $CIRCLE_PROJECT_ID using envsubst.

Instructions:

  1. CircleCI config.yml snippet:

    ...# Use envsubst to substitute variables
          - run:
              name: Generate deployment manifest
              command: |
                envsubst < deployment-template.yaml > deployment.yaml
                echo "Generated deployment.yaml:"
                cat deployment.yaml
          
          # Apply to Kubernetes
          - run:
              name: Deploy to Kubernetes
              command: |
                kubectl apply -f deployment.yaml 
  2. deployment-template.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        circleci.com/project-id: ${CIRCLE_PROJECT_ID}
        circleci.com/helm-revision-number: "1"
    ... 

Outcome:

The envsubst command will substitute the $CIRCLE_PROJECT_ID variable from the value in your workflow's environment. This eliminates the need to hard code and manually maintain the value.

Additional Resources:

Did this answer your question?