Skip to content

CI/CD

This page sets the rules for build and deployment pipelines in ConnectSoft repositories and in services generated from ConnectSoft templates. It is written for engineers who change azure-pipelines.yml or the shared step templates, and for reviewers of those changes.

How ConnectSoft pipelines are built

Every ConnectSoft repository builds in Azure DevOps from one azure-pipelines.yml at the repository root. There are two shapes.

Libraries and API clients (ConnectSoft.Extensions.*, the API client libraries) use an inline pipeline. The steps are: 1. restore; 2. check for deprecated and vulnerable packages; 3. build; 4. test with coverage; 5. apply the coverage quality check; 6. on the default branch only, pack and push to the Azure Artifacts feed (see Versioning and release).

Services and templates reference the step templates in the ConnectSoft.AzurePipelines repository, declared as the templates repository resource. Each area has its own steps:

Area Step templates
Build build/lint-microservice-steps.yaml, build/build-microservice-steps.yaml
Test test/test-microservice-steps.yaml, test/start-database-test-containers-steps.yaml
Publish and documentation publish/publish-microservice-steps.yaml, generate/generate-microservice-documentation-steps.yaml, generate/generate-microservice-reports-steps.yaml
Container build/build-and-push-microservice-docker-steps.yaml
Deploy deploy/deploy-microservice-to-iis.yaml, deploy/deploy-microservice-to-azure-container-apps.yaml and the other deploy templates

A service pipeline has a CI stage (build, test, publish) and one or more CD stages that deploy after a manual approval.

Template installers are validated every night by a separate pipeline, described in Nightly Template Validation Pipeline.

Rules

CS-PRC-007: Keep one pipeline file at the repository root

Severity: minor · Applies to: service, library, api-client, blazor, template, docs, pipelines · Enforced by: manual · Status: active

Why

Tools, templates and people look for azure-pipelines.yml at the root, where 491 of the 494 ConnectSoft pipeline files already are.

Do

  • Keep the build pipeline in azure-pipelines.yml at the repository root.
  • Name additional pipelines azure-pipelines.<purpose>.yml at the root, for example azure-pipelines.nightly.yml.

Don't

  • Move the pipeline into a pipelines/ or build/ folder.

How to check

The repository's main pipeline is azure-pipelines.yml at the root.

CS-PRC-008: Reuse the shared step templates in service and template pipelines

Severity: minor · Applies to: service, template, pipelines · Enforced by: manual · Status: active

Why

A fix to a shared step template reaches every service at once. A copied step drifts and keeps the old defect.

Do

  • Reference build, test, publish, documentation, container and deploy steps from ConnectSoft.AzurePipelines with template: <path>@templates.
  • When a service needs a variation, add a parameter to the shared template rather than copying it.

Don't

  • Copy the content of a shared step template into a service pipeline.
  • Change a shared template's default in a way that alters the behaviour of existing pipelines without a parameter. Shared defaults are behaviour; see ADR-0103.

How to check

  • New build, test, publish and deploy steps in a service pipeline are template: references to @templates.
  • A shared template change keeps the old behaviour as its default.

CS-PRC-009: Keep the dependency and coverage checks

Severity: major · Applies to: service, library, api-client, blazor, template, pipelines · Enforced by: manual (target: ENF-021) · Status: active

Why

The deprecated and vulnerable package checks catch supply-chain problems before a package is published. The coverage check enforces the coverage ratchet of ADR-0105.

Do

  • Keep the steps dotnet list package --deprecated and dotnet list package --vulnerable --include-transitive.
  • Keep the coverage quality check, with codeCoverageThreshold at its current value or higher.
  • Collect coverage with one collector per test run.

Don't

  • Remove or disable these steps, or set continueOnError: true on them, to get a build through.

How to check

  • The diff does not remove, disable or weaken the dependency checks or the coverage gate.
  • The test steps and the .runsettings file enable exactly one coverage collector.

CS-PRC-010: Deploy beyond development only after an approval

Severity: major · Applies to: service, pipelines · Enforced by: manual · Status: active

Why

An approval gate is the last point where a person can stop a bad build before it reaches a shared environment.

Do

  • Put each deployment to a testing, staging or production environment in its own stage, behind a manual approval or an Azure DevOps environment check.
  • Keep the CD stages conditional on a successful CI stage.

Don't

  • Deploy to a shared environment directly from the CI stage.
  • Remove an approval to speed up a release.

How to check

In the pipeline, every CD stage that targets a shared environment waits for an approval or an environment check, and depends on a successful CI stage.

CS-PRC-011: Check trigger paths and publish conditions against the repository

Severity: major · Applies to: library, api-client, template, pipelines · Enforced by: manual · Status: active

Why

A path filter that names a folder the repository does not have never starts the pipeline, and a publish condition that names a branch the repository does not use never publishes. Both fail silently: the pipeline reports nothing because it never ran, or it runs green and skips the push. Pipeline files copied between repositories carry the source repository's paths and branch name.

Do

  • Write trigger.paths entries relative to the repository root, including the src/ folder where projects live.
  • Name the repository's actual default branch in the pack and push conditions.
  • Re-check both when you copy a pipeline file from another repository or move projects.

Don't

  • List bare project names in trigger.paths.include.
  • Leave a publish condition on master in a repository whose default branch is main, or the other way round.

How to check

Every path in trigger.paths exists in the repository, and the branch in the publish conditions is the repository's default branch.

CS-PRC-012: Give CI service containers generated names and dynamic host ports

Severity: major · Applies to: service, template, pipelines · Enforced by: manual · Status: active

Why

Build agents run jobs from many pipelines. Two jobs that declare the same container name or host port race for it, and the loser, or any job after a crashed one, runs its tests without a database. The tests then fail with network errors that point at an innocent commit.

Do

  • Let the pipeline generate the container name.
  • Map the service port to a dynamic host port, and pass the mapped port to the tests through a pipeline variable.

Don't

  • Set --name on a service container.
  • Map a service container to a fixed host port.

How to check

Container resources in the pipeline have no --name option and no fixed host port.

CS-PRC-013: Write one test results file per test assembly

Severity: minor · Applies to: service, library, api-client, blazor, template, pipelines · Enforced by: manual · Status: active

Why

A fixed results file name on a solution-level test run makes every test assembly write the same file. The last assembly to finish wins, and the published results of a failed run can show only passing tests.

Do

  • Let the test logger name the results files, or include the assembly name in the file name.
  • Publish all results files of the run.

Don't

  • Set a fixed LogFileName on a dotnet test that runs more than one test assembly.

How to check

The published run has as many results files as the solution has test assemblies.

Pipeline secrets

Pipelines read secrets from secret variables, variable groups linked to Azure Key Vault, or service connections. A pipeline file never contains a secret value. This is rule CS-SEC-001.