> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/argoproj/argo-cd/llms.txt
> Use this file to discover all available pages before exploring further.

# Jsonnet

> Use Jsonnet templates with Argo CD

Argo CD supports Jsonnet for templating Kubernetes manifests. Any file matching `*.jsonnet` in a directory application is treated as Jsonnet and evaluated to generate manifests.

## Basic Jsonnet Application

Argo CD automatically detects Jsonnet files and evaluates them:

```yaml theme={null}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: jsonnet-app
spec:
  project: default
  source:
    repoURL: https://github.com/argoproj/argocd-example-apps.git
    targetRevision: HEAD
    path: jsonnet-guestbook
  destination:
    server: https://kubernetes.default.svc
    namespace: default
```

## External Variables

Pass external variables to Jsonnet templates:

```yaml theme={null}
spec:
  source:
    directory:
      jsonnet:
        extVars:
          - name: app
            value: $ARGOCD_APP_NAME
          - name: environment
            value: production
          - name: replicas
            value: "3"
```

<ParamField path="extVars" type="array">
  List of external variables passed to Jsonnet. Values are treated as strings.
</ParamField>

## Top-Level Arguments (TLAs)

Provide top-level arguments to Jsonnet:

```yaml theme={null}
spec:
  source:
    directory:
      jsonnet:
        tlas:
          - name: ns
            value: $ARGOCD_APP_NAMESPACE
          - name: clusterName
            value: production-cluster
```

<ParamField path="tlas" type="array">
  List of top-level arguments passed to Jsonnet functions
</ParamField>

## Shared Libraries

Add shared library paths (e.g., vendor folders) relative to the repository root:

```yaml theme={null}
spec:
  source:
    directory:
      jsonnet:
        libs:
          - vendor
          - lib
```

<ParamField path="libs" type="array">
  List of library paths available to Jsonnet imports
</ParamField>

## Complete Example

Application with all Jsonnet features:

```yaml theme={null}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: jsonnet-example
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/myorg/myrepo.git
    targetRevision: HEAD
    path: jsonnet-app
    directory:
      jsonnet:
        extVars:
          - name: app
            value: $ARGOCD_APP_NAME
          - name: environment
            value: production
        tlas:
          - name: ns
            value: $ARGOCD_APP_NAMESPACE
        libs:
          - vendor
  destination:
    server: https://kubernetes.default.svc
    namespace: production
```

## Build Environment

Jsonnet applications have access to standard build environment variables:

* `ARGOCD_APP_NAME` - The application name
* `ARGOCD_APP_NAMESPACE` - The application namespace
* `ARGOCD_APP_REVISION` - The git revision being deployed
* `ARGOCD_APP_SOURCE_REPO_URL` - The source repository URL
* `ARGOCD_APP_SOURCE_PATH` - The path within the repository
* `ARGOCD_APP_SOURCE_TARGET_REVISION` - The target revision

Use these in external variables and TLAs with the `$VARIABLE_NAME` syntax.

## CLI Usage

Configure Jsonnet via CLI:

```bash theme={null}
# Add external variable
argocd app create APPNAME \
  --jsonnet-ext-var-str 'app=${ARGOCD_APP_NAME}'

# Add TLA
argocd app create APPNAME \
  --jsonnet-tla-str 'ns=${ARGOCD_APP_NAMESPACE}'

# Add library path
argocd app create APPNAME \
  --jsonnet-libs 'vendor'
```

## Jsonnet Output

Argo CD evaluates Jsonnet and expects valid Kubernetes objects or arrays:

<CodeGroup>
  ```jsonnet Single Object theme={null}
  {
    apiVersion: 'v1',
    kind: 'ConfigMap',
    metadata: {
      name: 'my-config',
      namespace: 'default'
    },
    data: {
      key: 'value'
    }
  }
  ```

  ```jsonnet Array of Objects theme={null}
  [
    {
      apiVersion: 'v1',
      kind: 'ConfigMap',
      metadata: { name: 'config1' },
      data: { key: 'value1' }
    },
    {
      apiVersion: 'v1',
      kind: 'Service',
      metadata: { name: 'service1' },
      spec: { ports: [{ port: 80 }] }
    }
  ]
  ```
</CodeGroup>

<Tip>
  Use Jsonnet's powerful templating features to reduce duplication and dynamically generate manifests based on parameters.
</Tip>
