Operations
| Operation | Description |
|---|---|
UseImage | Set the Docker image for the current build container. Must be called before build steps execute. |
CopyArtifactsToHost | Register files to copy from the container to the host after the build completes. The first parameter is the path inside the container (relative to /workspace or absolute), and the second is the destination on the host (relative to project root or absolute). If a copy fails (refused destination, a destination that cannot be deleted, a failed docker cp), the run exits with 1 and the run record lists artifact-copy-failed. |
CopyZippedArtifactsToHost | Register files to be archived and copied from the container to the host after the build completes. Creates a single archive file for faster transfer of many small files. Supports .tar.gz (default) and .zip formats. If the destination is a directory, creates artifacts.tar.gz in that directory. |
Ando.Build | Run a nested build script. Accepts a directory (runs build.csando in that directory) or a specific .csando file path. The child build runs in its own isolated container with its own environment file ( .env.ando or .env) and context. Runs on the host, not in the container: this step starts a separate child ando build process, which creates its own container. It is the exception to "steps run in the container". The child is the same CLI that runs the parent (not whatever ando is first on PATH). --yes, --no-env and --no-color are forwarded. With --ref, the child builds the same commit with --ref and runs from the matching folder under the directory you ran from, not under the temporary worktree, so its artifacts, env file and run record land in the project. WithEnv(name, value, secret = false) sets a variable in the child process only (repeatable). When used, the child forwards exactly those variables into its containers instead of the variable names it inherits from the parent (also with --no-env). The value is redacted in both builds when the name looks secret (TOKEN, PASSWORD, KEY, ...) or secret: true. After the child exits, the run record gets an entry child record <path> (the child's path relative to the directory you ran from, for example child record website/build.csando; #2, #3 when the same path is built again) with the path of the child's run record. |
Ando.Block | Groups steps into a named block with optional failure and cleanup steps. The body runs at evaluation time to capture its steps; they run in order later. .OnFailure(Action) steps run only if a block step failed or the run was canceled (may be called more than once). .Finally(Action) steps always run. On failure the order is inner OnFailure, inner Finally, outer OnFailure, outer Finally. The block still fails the build after its OnFailure steps ran. C# try/finally around steps does not work, because steps run after the script is evaluated. |
Ando.Finally | Registers steps that always run at the end of the enclosing block, or at the end of the run at top level: after success, after a failure and after Ctrl+C. Finally steps run last-registered first and every one runs, even if an earlier one failed. All steps inside one Finally lambda run even if one fails. A Finally registered inside Ando.Defer or Ando.When runs when that body ends. |
Ando.Defer | Runs the lambda at execution time, when the steps before it have run, then runs the steps it registers. Use it to pass step outputs to later steps or to use plain C# if/foreach on runtime values. |
Ando.When | Runs the steps of then only if the condition is true at execution time, otherwise the steps of the optional otherwise. The condition can read step outputs. |
Ando.Require | Fails the build with the message if the condition is false at execution time. |
Ando.Cancelled | A bool that is true once the user pressed Ctrl+C. Read it at execution time, inside Ando.When, Ando.Require, Ando.Defer, OnFailure and Finally bodies; while the script is evaluated it is always false. OnFailure steps run after Ctrl+C too, so use it to tell a cancellation from a failure. |
Ando.Confirm | Asks [y/N] before the build continues. Declining fails the build. The overload that takes a Func<string> computes the message when the step runs; --dry-run shows it as (decided at run time). ando run --yes accepts every confirmation. Without --yes, a run with no interactive console fails at this step. |
Ando.StepTree | Registers a step whose Value is the --dry-run tree of file: one line per step, indented two spaces per level, with \n line endings and secrets redacted. Runs on the host: it starts the running CLI as run --dry-run --no-env --no-color -f file [-p profiles] from the directory you ran from, and with --ref when this run has one, so nothing in that script executes. A relative file is relative to that directory. A non-zero exit fails the step and logs the end of the child's output. It returns a CommandStep: WithTimeout (default: Ando.CommandTimeout or 5 minutes), WithEnv and AllowFailure work. Environment: the dry-run child inherits the parent's whole process environment (plus any WithEnv values). That is unlike Ando.Build with WithEnv, whose containers get only the WithEnv keys. Read Value at execution time. Do not call it on the script that contains the call. |
Ando.Report | Adds a value to the run record ( .ando/runs/*.json) when the step runs, and logs it. Overloads take a string, a StepOutput or a Func<string> evaluated at execution time. Secret values are redacted. |
Ando.CommandTimeout | Sets the timeout for command steps registered after this call (built-in default 5 minutes). Operations with their own longer default, such as AppService zip deploy, keep it. Use a step's WithTimeout for one step only. |
Ando.CopyToContainer | Copies a host file or directory into the build container. Relative host paths are relative to the directory ANDO was run from (also with --ref), so gitignored files such as local certificates can be used. Relative container paths are relative to /workspace. A directory replaces an existing directory at the container path. |
Ando.CopyToHost | Copies a file or directory from the build container to the host as a step, so later steps and later host work see it. The mirror of Ando.CopyToContainer. Relative host paths are relative to the directory ANDO was run from (also with --ref). Relative container paths are relative to /workspace. The existing destination is deleted first; the project folder and its parent folders are refused. Any error (refused destination, a destination that cannot be deleted, a failed docker cp) fails the step. Step context: <containerPath> -> <hostPath>. |
Ando.Lock | Takes the lock name now, while the script is evaluated, and holds it until the run ends. It is not a step: it does not appear in --dry-run output, and --dry-run takes no lock. If another run holds the lock, the run fails with exit code 9. Calling it again with the same name (or a name that maps to the same lock file, such as a/b and a_b) is a no-op. Call it at the top level of the script: inside Ando.Defer it runs at execution time, where a held lock fails that step (exit code 1, not 9). Child builds started with Ando.Build skip the names their parent holds (passed in ANDO_HELD_LOCKS). The lock is a file ~/.ando/locks/name-<name>.lock that the operating system releases when the process ends, even after a crash. The run record gets an entry lock <name>. Scope: it uses its own lock files under ~/.ando/locks (name-<name>.lock). It does not exclude other tools or scripts that flock a different file on the same target; use one locking mechanism per target. |
Ando.InvocationRoot | Host directory ANDO was run from (a string). Use it to read local, for example gitignored, files while the script is evaluated, also with --ref. |
Ando.WriteManifest | Registers a step that writes manifest.json into a container directory with the version, commit, and size and SHA-256 of every file. Copy the directory to the host with Ando.CopyArtifactsToHost and deploy it in a later run with Ando.ImportArtifacts. |
Ando.ImportArtifacts | Imports a build's artifacts for deployment and returns an ArtifactManifest with Version, Commit, Files (Path, Size, Sha256), File(pathOrName), PathOf(pathOrName) and ContainerPath. While the script is evaluated, ANDO verifies every file's SHA-256 on the host (missing, changed or extra files throw before any step runs). A registered step copies the directory into the container and verifies the hashes again. Relative host paths are relative to the directory ANDO was run from. The default container directory is the same relative path under /workspace. |
Operation Details
UseImage
source
Set the Docker image for the current build container. Must be called before build steps execute.
Ando.UseImage("ubuntu:24.04");
Ando.UseImage("mcr.microsoft.com/dotnet/sdk:9.0");
Ando.UseImage("node:22");CopyArtifactsToHost
source
Register files to copy from the container to the host after the build completes. The first parameter is the path inside the container (relative to /workspace or absolute), and the second is the destination on the host (relative to project root or absolute). If a copy fails (refused destination, a destination that cannot be deleted, a failed docker cp), the run exits with 1 and the run record lists artifact-copy-failed.
Ando.CopyArtifactsToHost("dist", "./dist");
Ando.CopyArtifactsToHost("bin/Release", "./output");CopyZippedArtifactsToHost
source
Register files to be archived and copied from the container to the host after the build completes. Creates a single archive file for faster transfer of many small files. Supports .tar.gz (default) and .zip formats. If the destination is a directory, creates artifacts.tar.gz in that directory.
Ando.CopyZippedArtifactsToHost("dist", "./output");
Ando.CopyZippedArtifactsToHost("dist", "./dist/binaries.tar.gz");
Ando.CopyZippedArtifactsToHost("dist", "./dist/binaries.zip");Ando.Build
source
Run a nested build script. Accepts a directory (runs build.csando in that directory) or a specific .csando file path. The child build runs in its own isolated container with its own environment file (.env.ando or .env) and context. Runs on the host, not in the container: this step starts a separate child ando build process, which creates its own container. It is the exception to "steps run in the container". The child is the same CLI that runs the parent (not whatever ando is first on PATH). --yes, --no-env and --no-color are forwarded. With --ref, the child builds the same commit with --ref and runs from the matching folder under the directory you ran from, not under the temporary worktree, so its artifacts, env file and run record land in the project. WithEnv(name, value, secret = false) sets a variable in the child process only (repeatable). When used, the child forwards exactly those variables into its containers instead of the variable names it inherits from the parent (also with --no-env). The value is redacted in both builds when the name looks secret (TOKEN, PASSWORD, KEY, ...) or secret: true. After the child exits, the run record gets an entry child record <path> (the child's path relative to the directory you ran from, for example child record website/build.csando; #2, #3 when the same path is built again) with the path of the child's run record.
Ando.Build(Directory("./website"));
Ando.Build(Directory("./website") / "deploy.csando");
Ando.Build(Directory("./api"), o => o.WithDind());
Ando.Build(Directory("./website"), o => o.WithEnv("CLOUDFLARE_API_TOKEN", token));Ando.Block
source
Groups steps into a named block with optional failure and cleanup steps. The body runs at evaluation time to capture its steps; they run in order later. .OnFailure(Action) steps run only if a block step failed or the run was canceled (may be called more than once). .Finally(Action) steps always run. On failure the order is inner OnFailure, inner Finally, outer OnFailure, outer Finally. The block still fails the build after its OnFailure steps ran. C# try/finally around steps does not work, because steps run after the script is evaluated.
Ando.Block("deploy", () =>
{
AppService.DeployFolder("my-app", "dist/api", "my-rg", o => o.WithDeploymentSlot("release"));
AppService.SwapSlots("my-app", "release", "my-rg");
})
.OnFailure(() => AppService.SwapSlots("my-app", "release", "my-rg"))
.Finally(() => AppService.Stop("my-app", "my-rg", "release"));Ando.Finally
source
Registers steps that always run at the end of the enclosing block, or at the end of the run at top level: after success, after a failure and after Ctrl+C. Finally steps run last-registered first and every one runs, even if an earlier one failed. All steps inside one Finally lambda run even if one fails. A Finally registered inside Ando.Defer or Ando.When runs when that body ends.
Ando.Finally(() => AppService.Stop("my-app", "my-rg", "release"));Ando.Defer
source
Runs the lambda at execution time, when the steps before it have run, then runs the steps it registers. Use it to pass step outputs to later steps or to use plain C# if/foreach on runtime values.
var host = AppService.GetHostName("my-app", "my-rg", "release");
Ando.Defer(() => Http.WaitForHealthy($"https://{host.Value}/healthz"));Ando.When
source
Runs the steps of then only if the condition is true at execution time, otherwise the steps of the optional otherwise. The condition can read step outputs.
var rules = AppService.AccessRestrictions("my-app", "my-rg", "release");
Ando.When(
() => rules.Json("ipSecurityRestrictionsDefaultAction") == "Deny",
() => Log.Info("Slot restricts access"),
() => Log.Info("Slot is open"));Ando.Require
source
Fails the build with the message if the condition is false at execution time.
var pending = Shell.Bash("./scripts/pending-migrations.sh");
Ando.Require(() => pending.Value == "", "Database has pending migrations");Ando.Cancelled
source
A bool that is true once the user pressed Ctrl+C. Read it at execution time, inside Ando.When, Ando.Require, Ando.Defer, OnFailure and Finally bodies; while the script is evaluated it is always false. OnFailure steps run after Ctrl+C too, so use it to tell a cancellation from a failure.
Ando.Block("deploy", () => { /* ... */ })
.OnFailure(() => Ando.When(() => !Ando.Cancelled, () => AppService.SwapSlots("my-app", "staging", "my-rg")));Ando.Confirm
source
Asks [y/N] before the build continues. Declining fails the build. The overload that takes a Func<string> computes the message when the step runs; --dry-run shows it as (decided at run time). ando run --yes accepts every confirmation. Without --yes, a run with no interactive console fails at this step.
Ando.Confirm("Swap release into production?");
Ando.Confirm(() => $"Swap {manifest.Version} into production?");Ando.StepTree
source
Registers a step whose Value is the --dry-run tree of file: one line per step, indented two spaces per level, with \n line endings and secrets redacted. Runs on the host: it starts the running CLI as run --dry-run --no-env --no-color -f file [-p profiles] from the directory you ran from, and with --ref when this run has one, so nothing in that script executes. A relative file is relative to that directory. A non-zero exit fails the step and logs the end of the child's output. It returns a CommandStep: WithTimeout (default: Ando.CommandTimeout or 5 minutes), WithEnv and AllowFailure work. Environment: the dry-run child inherits the parent's whole process environment (plus any WithEnv values). That is unlike Ando.Build with WithEnv, whose containers get only the WithEnv keys. Read Value at execution time. Do not call it on the script that contains the call.
var tree = Ando.StepTree("deploy.csando", profiles: "eu");
Ando.Report("deploy tree", tree);Ando.Report
source
Adds a value to the run record (.ando/runs/*.json) when the step runs, and logs it. Overloads take a string, a StepOutput or a Func<string> evaluated at execution time. Secret values are redacted.
var health = Http.Get("https://app.example.com/healthz");
Ando.Report("healthz", health);
Ando.Report("commit", Git.Commit);Ando.CommandTimeout
source
Sets the timeout for command steps registered after this call (built-in default 5 minutes). Operations with their own longer default, such as AppService zip deploy, keep it. Use a step's WithTimeout for one step only.
Ando.CommandTimeout(TimeSpan.FromMinutes(15));Ando.CopyToContainer
source
Copies a host file or directory into the build container. Relative host paths are relative to the directory ANDO was run from (also with --ref), so gitignored files such as local certificates can be used. Relative container paths are relative to /workspace. A directory replaces an existing directory at the container path.
Ando.CopyToContainer(".run/seal-1.pem", ".run/seal-1.pem");Ando.CopyToHost
source
Copies a file or directory from the build container to the host as a step, so later steps and later host work see it. The mirror of Ando.CopyToContainer. Relative host paths are relative to the directory ANDO was run from (also with --ref). Relative container paths are relative to /workspace. The existing destination is deleted first; the project folder and its parent folders are refused. Any error (refused destination, a destination that cannot be deleted, a failed docker cp) fails the step. Step context: <containerPath> -> <hostPath>.
Ando.CopyToHost("artifacts/manifest.json", "artifacts/manifest.json");Ando.Lock
source
Takes the lock name now, while the script is evaluated, and holds it until the run ends. It is not a step: it does not appear in --dry-run output, and --dry-run takes no lock. If another run holds the lock, the run fails with exit code 9. Calling it again with the same name (or a name that maps to the same lock file, such as a/b and a_b) is a no-op. Call it at the top level of the script: inside Ando.Defer it runs at execution time, where a held lock fails that step (exit code 1, not 9). Child builds started with Ando.Build skip the names their parent holds (passed in ANDO_HELD_LOCKS). The lock is a file ~/.ando/locks/name-<name>.lock that the operating system releases when the process ends, even after a crash. The run record gets an entry lock <name>. Scope: it uses its own lock files under ~/.ando/locks (name-<name>.lock). It does not exclude other tools or scripts that flock a different file on the same target; use one locking mechanism per target.
Ando.Lock("release");Ando.InvocationRoot
source
Host directory ANDO was run from (a string). Use it to read local, for example gitignored, files while the script is evaluated, also with --ref.
var local = Path.Combine(Ando.InvocationRoot, ".run", "settings.json");Ando.WriteManifest
source
Registers a step that writes manifest.json into a container directory with the version, commit, and size and SHA-256 of every file. Copy the directory to the host with Ando.CopyArtifactsToHost and deploy it in a later run with Ando.ImportArtifacts.
Ando.WriteManifest(Root / "artifacts", "1.4.0", Git.Commit);
Ando.CopyArtifactsToHost("artifacts", "./artifacts");Ando.ImportArtifacts
source
Imports a build's artifacts for deployment and returns an ArtifactManifest with Version, Commit, Files (Path, Size, Sha256), File(pathOrName), PathOf(pathOrName) and ContainerPath. While the script is evaluated, ANDO verifies every file's SHA-256 on the host (missing, changed or extra files throw before any step runs). A registered step copies the directory into the container and verifies the hashes again. Relative host paths are relative to the directory ANDO was run from. The default container directory is the same relative path under /workspace.
var m = Ando.ImportArtifacts("artifacts");
AppService.DeployFolder("my-app", m.PathOf("web"), "my-rg");
Log.Info($"Deploying {m.Version} ({m.Commit})");The Ando object holds build configuration, artifact handling, nested builds and the execution-time step model. Bare globals such as Root, Temp, Env(), Directory(), DefineProfile() and Log are not members of Ando; they are on the Globals page.
Build Configuration
Build configuration, artifact copying, and nested builds. Use these to set the Docker image, copy outputs to host, and run child build scripts.
Ando.Build is the exception to “steps run in the container”: its step runs on the host and starts a separate child ando build process, which creates its own container (own environment file, own context). The parent container does not run the child build.
// ando-doc-snippet-test
// Set the Docker image for the build container
Ando.UseImage("mcr.microsoft.com/dotnet/sdk:9.0");
// Copy artifacts from container to host after build
Ando.CopyArtifactsToHost("dist", "./dist");
// Copy as compressed archive (faster for many small files)
Ando.CopyZippedArtifactsToHost("dist", "./output"); // Creates ./output/artifacts.tar.gz
Ando.CopyZippedArtifactsToHost("dist", "./dist/binaries.tar.gz"); // Specific filename
Ando.CopyZippedArtifactsToHost("dist", "./dist/binaries.zip"); // Zip format
// Run a child build in a subdirectory
Ando.Build(Directory("./website"));
// Run a specific build file
Ando.Build(Directory("./website") / "deploy.csando");
// Child build with Docker-in-Docker enabled
Ando.Build(Directory("./integration-tests"), o => o.WithDind());
// Child build with a variable that exists in the child process only
Ando.Build(Directory("./website"), o => o.WithEnv("CLOUDFLARE_API_TOKEN", Env("CLOUDFLARE_API_TOKEN")));
The child is the same CLI that runs the parent, so ./ando-dev starts a source build and not the ando on PATH. A child inherits --yes and --no-env. When the parent runs with --ref, the child gets the same --ref and runs from the matching folder under the directory you ran from, not under the temporary worktree. Its artifacts, env file and run record then stay in the project. Without --ref, nothing changes.
WithEnv(name, value, secret = false) sets an environment variable in the child process only, never in the parent’s. It can be repeated. When you use it, the child forwards exactly those variables into its containers instead of the variable names it inherits from the parent. This also holds with --no-env. The value is redacted in both builds when the name looks secret (TOKEN, PASSWORD, KEY and similar) or you pass secret: true.
After the child exits, the parent’s run record gets an entry child record <path> (the child’s path relative to the directory you ran from, for example child record website/build.csando; #2, #3 when the same path is built again) with the path of the child’s run record. It is missing when the child wrote no record.
Step tree of another script
Ando.StepTree(file, profiles) returns the --dry-run tree of another script as the step’s Value: one line per step, two spaces of indent per level, \n line endings, secrets redacted. It starts the running CLI on the host with run --dry-run --no-env --no-color -f <file> (plus -p <profiles>, and --ref when this run has one), from the directory you ran from, so the script’s steps never run. A relative file is relative to that directory. A non-zero exit fails the step. It returns a CommandStep, so WithTimeout, WithEnv and AllowFailure work. The dry-run child inherits the parent’s whole process environment (plus any WithEnv values). This is unlike Ando.Build with WithEnv, whose containers get only the WithEnv keys. Read the value at execution time.
var tree = Ando.StepTree("deploy.csando", "eu");
Ando.Report("deploy tree", tree);
Options Reference
Build Options
| Option | Description |
|---|---|
WithVerbosity(string) | Set output verbosity level. Values: “Quiet” (errors only), “Minimal” (warnings and errors), “Normal” (default), “Detailed” (debug output). |
ColdStart(bool) | Force a fresh container for this build, ignoring any warm container cache. Use when you need a clean environment or are debugging container state issues. |
WithDind(bool) | Enable Docker-in-Docker mode. Required when the child build needs to run Docker commands (e.g., building images, running docker-compose). Mounts the Docker socket into the container. |
WithImage(string) | Override the Docker image for this child build. Use when the child build requires different tools than the parent (e.g., Node.js build in a .NET project). |
WithEnv(string, string, bool) | Set an environment variable in the child process only (repeatable). The child forwards exactly these variables into its containers. Redacted when the name looks secret or secret: true. |
Step model
Steps register while the script is evaluated and run afterwards, in order, stopping at the first failure. C# try/finally, if and foreach around step calls therefore run at evaluation time, not at execution time, and a step’s output does not exist yet. These operations on Ando give you the same structure at execution time.
| Need | Use |
|---|---|
| Group steps, handle failure, clean up | Ando.Block(name, body).OnFailure(...).Finally(...) |
| Steps that always run at the end of the enclosing block or run | Ando.Finally(body) |
| Run C# at execution time, then the steps it registers | Ando.Defer(body) |
| Run steps only if a runtime condition holds | Ando.When(condition, then, otherwise?) |
| Fail the build if a runtime condition is false | Ando.Require(condition, message) |
| Ask before continuing | Ando.Confirm(string | Func<string>) |
| Record a value in the run record | Ando.Report(key, string | StepOutput | Func<string>) |
| Default timeout for command steps | Ando.CommandTimeout(TimeSpan) |
Tell a Ctrl+C from a failure in OnFailure/Finally | Ando.Cancelled (read at execution time) |
Ordering on failure and cancellation
- A failing step stops its scope (the run, a block or a deferred body).
- For a failed block, the
OnFailuresteps run first, then theFinallysteps. The block still fails, and the failure moves to the enclosing scope. - With nested blocks the order is: inner
OnFailure, innerFinally, outerOnFailure, outerFinally. Finallysteps of a scope run last-registered first, and every one runs even if an earlier one failed. Within oneFinallylambda, all steps run even if one fails.- Within one
OnFailurelambda, the first failing step stops the remaining steps of that lambda. OtherOnFailurecalls on the same block still run. - Finally steps belong to the enclosing
Ando.Block(or the run).DeferandWhenbodies are transparent: a finally step registered inside one, including the removal registered byAppService.TemporaryAccessRule, runs when the enclosing block ends, not when the body ends. - Ctrl+C: the first Ctrl+C stops the running step (it is marked cancelled), stops any command it left running in the build container, then runs the on-failure and finally steps. Commands started after the first press ignore further Ctrl+C presses, so a second press only prints a warning. A third press exits immediately (exit code 130) and skips the remaining cleanup; within 5 seconds it still tries to remove the
--refworktree and writes the run record with"aborted": true(for warm containers the temporary Azure profile is removed at the start of the next run;--coldremoves it with the container). Any run interrupted with Ctrl+C exits with 130 (a failure exits with 1).OnFailuresteps run after Ctrl+C as well; readAndo.Cancelledto tell the two apart.
Ando.Cancelled
Ando.Cancelled is a bool that is true once the user pressed Ctrl+C. Read it at execution time, inside Ando.When, Ando.Require, Ando.Defer, OnFailure and Finally bodies. While the script is evaluated it is always false. OnFailure steps run after Ctrl+C too, so use it to tell a cancellation from a failure:
Ando.Block("deploy", () => { /* ... */ })
.OnFailure(() => Ando.When(() => !Ando.Cancelled, () => AppService.SwapSlots(app, "staging", rg)));
Reading step output
Shell.Run, Shell.Bash, Azure.Cli, Git.RevParse, Git.LatestTag, Git.ChangedFiles, AppService.SwapSlots, AppService.Stop, AppService.Start, AppService.Restart, AppService.Show, AppService.GetHostName and AppService.AccessRestrictions (and the same operations on Functions) return a CommandStep. Http.Get, Http.PublicIpV4 and Azure.Vm.RunCommand return a StepOutput. Both have:
Value: trimmed stdout, or the response body for HTTP steps.ExitCode: exit code of a command step.StatusCode: HTTP status code for HTTP steps; throws for other steps.Json(path): a dotted path with optional array indexes, such assiteConfig.ipSecurityRestrictions[0].name. Property names match case-insensitively. Returns the string value, the raw JSON for objects and arrays, ornullwhen the path is missing or the value is JSON null.
Reading any of these before the step ran throws. Read them inside an execution-time lambda (Defer, When, Require, Report, or a Func<> overload such as Http.WaitForHealthy(() => ...)).
CommandStep adds fluent configuration that takes effect when the step runs: InDirectory(path), WithTimeout(TimeSpan), WithEnv(name, value), AllowFailure() and Quiet().
Example: slot deploy with gates and swap-back
// ando-doc-snippet-test
// Run with: ando run --ref v1.4.0 --yes
var app = "my-web-app";
var rg = "my-rg";
Ando.UseImage("mcr.microsoft.com/dotnet/sdk:10.0");
// Evaluation-time checks: fail before any step runs.
Git.RequireClean("src", "web");
var manifest = Ando.ImportArtifacts("artifacts");
Azure.EnsureAuthenticated();
var releaseHost = AppService.GetHostName(app, rg, "release");
var prodHost = AppService.GetHostName(app, rg);
Ando.Block("deploy", () =>
{
// Removed again when this block ends, whatever happened.
AppService.TemporaryAccessRule(app, rg, "release", "deploy-gate");
AppService.DeployFolder(app, manifest.PathOf("web"), rg, o => o.WithDeploymentSlot("release"));
Http.WaitForHealthy(
() => new[] { $"https://{releaseHost.Value}/healthz", $"https://{releaseHost.Value}/healthz/db" },
o => o.ConsecutiveSuccesses(3).MinGapSeconds(10).ExpectJson("version", manifest.Version));
Ando.Confirm("Swap release into production?");
Ando.Block("swap", () =>
{
AppService.SwapSlots(app, "release", rg);
Http.WaitForHealthy(() => $"https://{prodHost.Value}/healthz", o => o.ConsecutiveSuccesses(2));
})
.OnFailure(() => AppService.SwapSlots(app, "release", rg)); // swap back
})
.Finally(() => AppService.Stop(app, rg, "release"));
Ando.Report("version", manifest.Version);
If the post-swap health check fails, the swap-back runs first (inner OnFailure), then the outer Finally steps in reverse registration order: the release slot is stopped, then the deploy-gate rule is removed and its removal verified. The build still fails.
Build once, deploy the same bytes
Ando.WriteManifest(directory, version, commit) registers a step that writes manifest.json into a container directory with the version, commit, and size and SHA-256 of every file. Copy the directory to the host with Ando.CopyArtifactsToHost. In a later run, Ando.ImportArtifacts(hostDirectory, containerDirectory = null) reads the manifest while the script is evaluated and verifies every file’s hash on the host. Missing, changed or extra files throw before any step runs. A registered step then copies the directory into the container and verifies the hashes again there.
ImportArtifacts returns an ArtifactManifest:
| Member | Description |
|---|---|
Version, Commit | Values recorded by the build. |
Files | Every file with Path, Size and Sha256. |
File(pathOrName) | Finds a file by relative path, or by file name when unique. Throws if not found. |
PathOf(pathOrName) | Container path of a file, or of a directory that contains files (PathOf("web")). |
ContainerPath | Container path of the imported directory. |
Relative host paths are relative to the directory ANDO was run from. The default container directory is the same relative path under /workspace.
// ando-doc-snippet-test
// Build run
Ando.WriteManifest(Root / "artifacts", "1.4.0", Git.Commit);
Ando.CopyArtifactsToHost("artifacts", "./artifacts");
Host files and the invocation directory
Ando.CopyToContainer(hostPath, containerPath) copies a host file or directory into the build container. Relative host paths are relative to the directory ANDO was run from, also with ando run --ref, so gitignored files such as local certificates can be used. Relative container paths are relative to /workspace. A directory replaces an existing directory at the container path. Ando.InvocationRoot is that host directory as a string, for reading local files while the script is evaluated. Ando.SourceRoot is the host directory of the source tree being built: the temporary worktree with --ref, otherwise the project directory.
Ando.CopyToContainer(".run/seal-1.pem", ".run/seal-1.pem");
Copying from the container in step order
Ando.CopyToHost(containerPath, hostPath) is the mirror of Ando.CopyToContainer: it copies a file or directory from the build container to the host as a step, in order with the other steps. Relative host paths are relative to the directory ANDO was run from (also with --ref). The existing destination is deleted first, and the project folder and its parents are refused. Any error fails the step. Ando.CopyArtifactsToHost copies after the last step instead; a failed copy there makes the run exit with 1.
Ando.CopyToHost("artifacts/manifest.json", "artifacts/manifest.json");
Locks
Each run takes a lock on its build container, so a second run of the same script fails at once with exit code 9 (see Run locks). Ando.Lock("name") takes a named lock while the script is evaluated and holds it until the run ends, for work that must not overlap, such as a release. It is not a step, so it is not in --dry-run output, and --dry-run takes no lock. Call it at the top level of the script: inside Ando.Defer it runs at execution time, where a held lock fails that step (exit code 1, not 9). Names that map to the same lock file (a/b and a_b) are one lock. Child builds skip the names their parent holds. The run record lists it as lock <name>. It uses its own lock files under ~/.ando/locks (name-<name>.lock), so it does not exclude other tools or scripts that flock a different file on the same target. Use one locking mechanism per target.
Ando.Lock("release");
Run record
Every ando run writes .ando/runs/<utc-time>.json in the directory you ran from. It lists the steps that ran, including steps inside blocks and on-failure and finally steps, with depth, cleanup, start and end time, result and error, plus the values added with Ando.Report. .ando/runs/ has its own .gitignore. Secret values are redacted: environment variables whose names contain SECRET, PASSWORD, TOKEN, KEY and similar words are replaced with [REDACTED] in console output, the build log and run records.