---
title: "Unset GitHub Actions variables defeat Bicep readEnvironmentVariable defaults"
url: "https://www.dariuszparys.com/notes/unset-github-actions-variables-defeat-bicep-defaults"
author: "Dariusz Parys"
published: 2026-11-19T00:00:00.000Z
description: "A workflow that passes an unset variable defines it as an empty string, so Bicep's readEnvironmentVariable never falls back to its default and the deployment fails only in CI."
---

# Unset GitHub Actions variables defeat Bicep readEnvironmentVariable defaults

## Context

A Bicep parameter file reads a setting with a default, and a GitHub Actions workflow passes the matching repository or environment variable through to the deploy step.

```bicep
ttlMinutes: int(readEnvironmentVariable('APP_TTL_MINUTES', '20'))
```

## Insight

`readEnvironmentVariable('NAME', 'default')` falls back to the default only when the variable **does not exist**. A workflow line like

```yaml
env:
  APP_TTL_MINUTES: ${{ vars.APP_TTL_MINUTES }}
```

always defines the variable. When `vars.APP_TTL_MINUTES` is unset, the variable is an **empty string**, so Bicep reads `''` instead of the default, and `int('')` fails the deployment.

A deploy from a laptop gets the default (the variable doesn't exist there), but CI fails. That makes this easy to miss in local testing.

## Fix

1. Put the default in the workflow too:

   ```yaml
   APP_TTL_MINUTES: ${{ vars.APP_TTL_MINUTES || '20' }}
   ```

2. Validate the value before the deploy step, so a bad value fails fast with a clear message.

   In PowerShell, use a strict regex, not only `[int]::TryParse`. TryParse accepts leading and trailing whitespace (`' 15 '`), which Bicep's `int()` may reject:

   ```powershell
   $minutes = 0
   if ($Value -notmatch '^[0-9]{1,2}$' -or
       -not [int]::TryParse($Value, [ref]$minutes) -or
       $minutes -lt 1 -or $minutes -gt 60) {
     throw "APP_TTL_MINUTES must be a whole number from 1 to 60, but is '$Value'."
   }
   ```

3. Optionally, add a CI regression check that the workflow line still carries the `|| 'default'` fallback.
