Lesson 4 of 4 Foundry Infrastructure and Deployments

Delivering Foundry Projects with CI/CD Pipelines

This lesson explains how Foundry projects integrate with continuous integration and continuous deployment (CI/CD), so infrastructure, deployments, agent definitions and quality checks all flow through pipelines.

Learning outcomes

After completing this lesson, you will be able to:

  • Define Foundry resources with Bicep or Terraform.
  • Explain how workload identity federation authenticates pipelines without secrets.
  • Describe the pipeline stages for agents and evaluations.

Infrastructure as code

An AI solution has more moving parts than a conventional application, and most of them change behaviour without any code change. A new model version, an edited instruction, a different tool description or a re-chunked index can each make answers better or worse. If these changes are made by hand in the portal, nobody can say exactly what changed between a good week and a bad one, and the test and production environments drift apart. CI/CD for Foundry treats all of them as versioned artifacts that move through the same pipeline: infrastructure is defined as code, agent definitions and prompts live in source control, and evaluations act as automated tests.

Infrastructure is the first layer. Bicep and Terraform define the Foundry resource, projects, model deployments, connections, private endpoints and role assignments, so that every environment is created from the same definition. In Bicep, the resource is Microsoft.CognitiveServices/accounts with kind: 'AIServices' and allowProjectManagement: true, projects are accounts/projects and deployments are accounts/deployments. Azure Developer CLI templates package IaC with application code so that azd up provisions and deploys an environment.

The following Bicep defines a Foundry resource with a system-assigned managed identity, project management enabled and key authentication disabled, and a Global Standard deployment of 50,000 tokens per minute named by purpose.

resource foundry 'Microsoft.CognitiveServices/accounts@2025-06-01' = {
  name: foundryName
  location: location
  kind: 'AIServices'
  sku: { name: 'S0' }
  identity: { type: 'SystemAssigned' }
  properties: {
    customSubDomainName: foundryName
    allowProjectManagement: true
    disableLocalAuth: true
  }
}

resource chat 'Microsoft.CognitiveServices/accounts/deployments@2025-06-01' = {
  parent: foundry
  name: 'chat-primary'
  sku: { name: 'GlobalStandard', capacity: 50 }
  properties: { model: { format: 'OpenAI', name: 'gpt-5-mini', version: '2025-08-07' } }
}
Match the pairs

Foundry in Bicep

Exam skills 1.2.4

Match each infrastructure item with how it is defined or deployed.

Log in to try this activity Interactive activities are free with an account.

Pipeline authentication

GitHub Actions and Azure Pipelines authenticate to Azure with workload identity federation: the pipeline presents a short-lived OpenID Connect token that Microsoft Entra ID exchanges for an access token for a user-assigned managed identity or app registration. No client secret or API key is stored in the pipeline. The identity receives only the roles it needs, for example Contributor on the resource group for deployments and Foundry User on the project to create agent versions and run evaluations.

Agents and evaluations in the pipeline

Agent instructions, tool definitions, prompts and evaluation datasets are stored in source control next to the application code, so that a pull request shows exactly how an agent's behaviour will change. The pipeline then treats a new agent version like a new build. It is created in a test project, measured with the evaluation dataset, and promoted to production only if its scores meet the thresholds. The important difference from conventional testing is that the gate is a score rather than a pass or fail assertion, because generative output varies. A typical pipeline has the following stages.

  • Build: lint and unit-test application code and tool functions.
  • Provision: apply Bicep or Terraform to the test environment.
  • Deploy agent: create a new agent version in the test project with the SDK.
  • Evaluate: run quality, agent and safety evaluators on the evaluation dataset and compare with thresholds.
  • Promote: if thresholds pass, apply the same definitions to production, often after a manual approval.

Gating on evaluation scores catches regressions such as a prompt change that lowers groundedness or a tool description change that causes wrong tool calls. After release, continuous evaluation in production watches for drift.

The following diagram shows how the pipeline signs in and where the evaluation gate stops a release.

A GitHub Actions workflow presents an OIDC token to Microsoft Entra ID and receives an access token for a managed identity, so no secret is stored. The release runs build, provision, deploy agent, evaluate, approve and promote. If evaluation scores fall below the threshold the job fails and production is unchanged; after release, continuous evaluation watches for drift.
Workload identity federation replaces stored secrets, and the evaluation stage blocks promotion when scores fall below the threshold, such as a mean groundedness of 4.0.

The Foundry portal shows each agent version as YAML, which is the form that is kept in source control. The following screenshot shows the definition of an order support agent: its kind, model deployment, instructions and reasoning effort, and an MCP tool limited to one allowed tool with approval required.

YAML definition of an agent version with kind prompt, model chat-primary, instructions, reasoning effort and an MCP tool with allowed_tools and require_approval
A change to the instructions or tools in this file goes through a pull request and an evaluation like any code change.
Put in order

A Foundry release pipeline

Exam skills 1.2.4

Put the stages of a Foundry release pipeline in order.

Log in to try this activity Interactive activities are free with an account.
Worked example

Securing a deployment pipeline

A team's GitHub Actions workflow deploys a Foundry agent and currently stores an API key and a service principal secret as repository secrets. The security team requires that no long-lived secrets be stored, and that releases be blocked if groundedness falls below 4.0.

Replace the secrets with workload identity federation: create a federated credential on a managed identity for the repository and branch, use the azure/login action with OIDC, and grant the identity the required roles. Remove the API key and use Entra ID in the evaluation and agent scripts. Add an evaluation step that computes the mean groundedness on the test dataset and fails the job below 4.0.

Check yourself

How should a deployment pipeline authenticate to Azure?

Show answer

With workload identity federation (OIDC), so no secret is stored in the pipeline.

Exam Tips

Remember for the exam

  • Pipelines authenticate with workload identity federation (OIDC), not stored secrets.
  • Bicep: accounts (kind AIServices), accounts/projects, accounts/deployments.
  • Gate promotion on evaluation thresholds; keep agent definitions and datasets in source control.