Skip to main content
Run env zero self-hosted agents as ephemeral Azure Container Apps (ACA) Jobs that scale to zero when idle and spin up automatically when deployments are queued. Scaling is driven by KEDA, which is built into the Azure Container Apps managed environment, so no separate KEDA installation is required.
Self-hosted agents are available to Enterprise customers only. See pricing for details.

How It Works

KEDA polls the env zero agent queue state endpoint on a fixed interval and creates ACA job executions when deployment tasks are queued. Each container picks up one task, runs it to completion, and exits. When the queue is empty, no containers run.

Prerequisites

  • Azure CLI installed and authenticated (az login)
  • Azure subscription with Contributor access
  • An env zero agent pool with a valid agent access token. See Self-Hosted Agents Overview for how to create an agent pool and generate a secret.

Setup

1

Create a resource group

2

Create a Container Apps environment

This creates a managed environment with KEDA built in. No KEDA installation is needed.
3

Create the job configuration file

Save the following as env0-aca-job.yaml. Replace <YOUR_AGENT_ACCESS_TOKEN> with the agent access token generated for your agent pool, <YOUR_STATE_ENCRYPTION_KEY_BASE64> with a base64-encoded encryption key, and <X.Y.Z> with the agent version you want to pin to.
env0-aca-job.yaml
4

Create the job

ENV0_STATE_ENCRYPTION_KEY must be a base64-encoded value and identical across all agent replicas. Mismatched keys make encrypted deployment state unreadable, which results in data loss.
Pin image to a specific agent version rather than :latest to avoid silent upgrades during a running deployment. See the env0 deployment agent releases for current tags.

Configuration Reference

KEDA Scaling Parameters

Container Resources

Environment Variables

Monitoring

List running and completed executions:
View logs for a specific execution:
Stop a running execution:

Troubleshooting

No containers start when deployments are queued

Check the KEDA system logs for the Container Apps environment:
Common causes:
  • api returned 401: the agent access token is incorrect or has been revoked. Generate a new secret and update the job configuration.
  • No KEDA activity logged: verify the job was created with triggerType: Event.

A container starts but fails immediately

Check the container logs for the specific error. Common causes:
  • Missing ENV0_STAGE: deployment commands build URLs from this variable and produce broken hosts when it is unset. Set it explicitly to prod for production.
  • Missing ENV0_STATE_ENCRYPTION_KEY: the agent exits immediately with an error.
  • Wrong AGENT_ACCESS_TOKEN: the agent starts but receives 401 on API calls.

Cleanup

To remove all resources created for this setup:

Next Steps