Azure Developer CLI (azd)

repository·main·Indexed 19 days ago

https://github.com/azure/azure-dev

A developer-centric CLI designed to streamline building, deploying, and operating Azure applications. Includes extensions for managing Microsoft Foundry Projects, AI agents, connections, and the Azure AI Inspector for local agent debugging.

Tokens
294.4K
Snippets
781
Records
1.2K
Agent score
68%

What's inside azd

  1. Use the `azd` AI Builder Extension to integrate AI into applications

    main
    The azd AI Builder extension is a guided, scenario-driven assistant for the Azure Developer CLI (azd). It helps you discover and provision the appropriate Azure resources required for specific AI use cases, such as Retrieval-Augmented Generation (RAG) systems, intelligent agents, or custom AI workflows. The extension uses LLM-aware prompts and best-practice architectures to guide you from Proof of Concept (POC) to production.
  2. Manage Microsoft Foundry skills with azd ai skill

    main

    The azure.ai.skills extension allows you to manage Microsoft Foundry skills (reusable behavioral guidelines for agents) from your terminal. Skills are versioned and immutable.

    When you create a skill, it uploads the first default version. When you update a skill, it uploads a new immutable version and promotes it to the default_version. You can revert to or access older versions using --set-default-version <version> or by downloading a specific version with azd ai skill download --version <ver>.

    # Example: Creating a skill from a directory
    azd ai skill create my-skill --file ./skill-src/
    
    # Example: Updating a skill with inline instructions
    azd ai skill update my-skill --instructions "New instructions here"
  3. What is a CommandJob in Azure AI ML SDK

    main

    A CommandJob is the fundamental job type in the Azure AI ML SDK. It executes a single command on a specified compute target with defined inputs, outputs, and environment configuration.

    A CommandJob is composed of four functional layers:

    1. Resource: Handles metadata and serialization.
    2. Job: Manages job-level configuration.
    3. ParameterizedCommand: A mixin for command execution details.
    4. JobIOMixin: A mixin for input/output handling.
  4. Access persistent flags from child commands

    main

    When a parent command (like root) defines persistent flags, store them in a global variable within that package. Child commands can then reference this global variable directly to access the flag values.

    // In root.go
    var rootFlags struct {
        Debug    bool
        NoPrompt bool
    }
    
    func NewRootCommand() *cobra.Command {
        cmd := &cobra.Command{...}
        cmd.PersistentFlags().BoolVar(&rootFlags.NoPrompt, "no-prompt", false, "...")
        return cmd
    }
    
    // In child commands
    func runInit(ctx context.Context, flags *initFlags) error {
        if rootFlags.NoPrompt {
            // Use no-prompt mode
        }
        return nil
    }
  5. How local provision validation works

    main

    Local provision validation is a client-side check that executes during azd provision after Bicep compilation but before the template is sent to Azure.

    The Workflow:

    1. Compile Bicep module: Generates the ARM template and parameters.
    2. Local provision validation:
      • Parses the ARM template.
      • Generates a Bicep snapshot (a fully resolved deployment graph).
      • Analyzes resources to derive properties.
      • Runs registered check functions.
    3. Server-side ARM preflight: Calls the Azure ValidatePreflight API.
    4. Deploy: Executes the deployment in Azure.
  6. Handle `infra.provider` polymorphism in telemetry queries

    main

    The infra.provider field is emitted with different data types depending on the command being executed. When writing queries, you must account for both scalar strings and string arrays.

    • provision / up / down: Emits a string array (string[]) containing the sorted, de-duplicated set of IaC providers (e.g., ["bicep", "terraform"]).
    • infra generate / infra synth: Emits a single string (string) representing the value from azure.yaml's infra.provider (defaults to "auto"). Non-built-in providers are bucketed as "custom".

    Important Nuances:

    • Bucketing: Extension providers are bucketed to "custom" before de-duplication. A project using two different extension providers will appear as ["custom"].
    • Scoping: This field is attached directly to the command's span (e.g., cmd.provision) and is not inherited by child commands like cmd.deploy or cmd.package.
  7. Interpret job suffixes (bX and ibY) in the PR matrix

    main

    When viewing pull request jobs, you may see suffixes like b1 or ib1. These are automatically added by the matrix creation logic to handle batching:

    • bX (e.g., b1, b2): Indicates a batch of direct packages. Packages are grouped by their matrix configuration (from their ci.yml) and then split into batches based on a configurable batchSize (defaulting to 10).
    • ibX (e.g., ib1): Indicates a batch of indirect packages. These are also batched, but instead of using the full test matrix, the system deterministically selects a single item from the resolved test matrix to assign the batch to.
  8. Error handling and Context propagation in Go

    main

    When implementing Go logic in azd:

    • Errors: Always wrap errors using fmt.Errorf with the %w verb to provide actionable context and maintain trace IDs.
    • Context: Always propagate context.Context through function calls to ensure proper cancellation and telemetry support.
    func (s *Service) Run(ctx context.Context) error {
        if err := s.doWork(ctx); err != nil {
            return fmt.Errorf("failed to provision resources: %w", err)
        }
        return nil
    }
  9. Understand outcomes of canceling an Azure deployment

    main

    When you select the Cancel the Azure deployment option, the final state of your resources depends on how quickly Azure processes the request. The following outcomes are possible:

    OutcomeDescription
    Cancellation confirmedAzure transitions the deployment to Canceled within the 5-minute budget. azd exits with a non-zero status.
    Cancel raced succeededAzure reached Succeeded before the cancel request took effect. Your resources are deployed; azd will report this with a success-toned message.
    Cancel raced failedAzure reached Failed before the cancel request took effect. azd reports the failure and provides the portal URL.
    Cancel raced deletedThe deployment record was deleted (e.g., by an external actor) before the cancel could take effect.
    Cancel still pendingAzure did not reach a terminal state within the 5-minute budget. azd warns you that cancellation may still complete and provides the portal URL.
    Cancel request failedThe ARM Cancel API returned an error. The deployment is likely still running; use the provided portal URL to check status.