Ci Cd

codewithmukesh/dotnet-claude-kit/skills/ci-cd

作者 codewithmukesh23300897f4d1无许可证754 个星标收录于 2026年10月8日更新于 2026年10月8日仓库2个月前更新

CI/CD pipelines for .NET applications. Covers GitHub Actions and Azure DevOps YAML pipelines with build, test, publish, and deploy stages. Load this skill when setting up continuous integration, automated testing, deployment workflows, or when the user mentions "CI/CD", "pipeline", "GitHub Actions", "Azure DevOps", "workflow", "deploy", "build pipeline", "publish", "NuGet push", "release", or "continuous integration".

仅含说明DevOps & Cloud
AI 生成的概览

指导为 .NET 应用搭建 CI/CD 流水线,涵盖 GitHub Actions 与 Azure DevOps YAML。

功能
该技能为 .NET 应用提供持续集成与交付流水线的指导和 YAML 示例。内容涵盖 GitHub Actions 与 Azure DevOps 工作流,包括还原、构建、格式检查、测试、发布和部署阶段,以及 Docker 镜像和 NuGet 包发布。此外还列出反模式并给出平台选择决策指南。
适用场景
适用于为 .NET 项目搭建持续集成、自动化测试或部署工作流的场景。也适合提到 CI/CD、流水线、GitHub Actions、Azure DevOps、构建流水线、发布或 NuGet push 的请求。
运行要求
不包含脚本,仅为说明文档和 YAML 示例。运行所述流水线需要具备 GitHub Actions 或 Azure DevOps 的代码仓库、.NET SDK,以及 NuGet API 密钥或容器镜像仓库令牌等凭据。

CI/CD

Core Principles

  1. Pipeline as code — YAML pipelines committed to the repo. No click-ops in the UI.
  2. Fast feedback — Build and test on every push. Cache NuGet packages. Fail fast.
  3. Build once, deploy many — Build the artifact once, promote it through environments (dev → staging → production).
  4. Never skip tests — Tests gate the pipeline. No deployment without passing tests.

Patterns

GitHub Actions — Build + Test

yaml
# .github/workflows/ci.ymlname: CI
on:  push:    branches: [main]  pull_request:    branches: [main]
env:  DOTNET_VERSION: '10.0.x'  DOTNET_NOLOGO: true  DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:  build-and-test:    runs-on: ubuntu-latest
    services:      postgres:        image: postgres:18        env:          POSTGRES_DB: testdb          POSTGRES_USER: postgres          POSTGRES_PASSWORD: postgres        ports:          - 5432:5432        options: >-          --health-cmd pg_isready          --health-interval 10s          --health-timeout 5s          --health-retries 5
    steps:      - uses: actions/checkout@v5
      - name: Setup .NET        uses: actions/setup-dotnet@v5        with:          dotnet-version: ${{ env.DOTNET_VERSION }}
      - name: Restore        run: dotnet restore
      - name: Build        run: dotnet build --no-restore --configuration Release
      - name: Format check        run: dotnet format --verify-no-changes --no-restore
      - name: Test        run: dotnet test --no-build --configuration Release --logger trx --results-directory TestResults        env:          ConnectionStrings__Default: "Host=localhost;Database=testdb;Username=postgres;Password=postgres"
      - name: Publish test results        uses: actions/upload-artifact@v5        if: always()        with:          name: test-results          path: TestResults/*.trx

GitHub Actions — Build + Publish Docker Image

yaml
# .github/workflows/publish.ymlname: Publish
on:  push:    tags: ['v*']
jobs:  publish:    runs-on: ubuntu-latest    permissions:      contents: read      packages: write
    steps:      - uses: actions/checkout@v5
      - name: Login to GitHub Container Registry        uses: docker/login-action@v3        with:          registry: ghcr.io          username: ${{ github.actor }}          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Extract version from tag        id: version        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
      - name: Build and push        uses: docker/build-push-action@v6        with:          context: .          push: true          tags: |            ghcr.io/${{ github.repository }}:${{ steps.version.outputs.VERSION }}            ghcr.io/${{ github.repository }}:latest

Azure DevOps — Build + Test

Same restore → build → format → test flow as GitHub Actions. Key differences:

yaml
# azure-pipelines.ymltrigger:  branches:    include: [main]  paths:    exclude: ['*.md', docs/]
pool:  vmImage: 'ubuntu-latest'          # vs runs-on: ubuntu-latest
variables:  dotnetVersion: '10.0.x'
# Key task differences from GitHub Actions:#   Setup .NET:  task: UseDotNet@2  (inputs: version: $(dotnetVersion))#   Test results: task: PublishTestResults@2  (testResultsFormat: VSTest)#   Steps use `script:` + `displayName:` instead of `- name:` + `run:`#   Services (e.g., Postgres) require a separate Docker task or pipeline service connection

NuGet Package Publishing

yaml
# Part of GitHub Actions workflow- name: Pack  run: dotnet pack src/MyLibrary -c Release -o ./nupkg --no-build
- name: Push to NuGet  run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

Anti-patterns

Don't Build Different Artifacts per Environment

yaml
# BAD — building separately for each environment- script: dotnet publish -c Debug   # for dev- script: dotnet publish -c Release # for prod
# GOOD — build once, deploy everywhere- script: dotnet publish -c Release -o ./publish# Then deploy the same ./publish artifact to dev, staging, prod

Don't Skip Format Checks in CI

yaml
# BAD — no format enforcementsteps:  - run: dotnet build  - run: dotnet test
# GOOD — format check catches style issues earlysteps:  - run: dotnet build  - run: dotnet format --verify-no-changes  - run: dotnet test

Don't Hardcode Secrets in Pipelines

yaml
# BAD — secret in pipeline YAMLenv:  DB_PASSWORD: "my-secret-password"
# GOOD — use pipeline secretsenv:  DB_PASSWORD: ${{ secrets.DB_PASSWORD }}

Decision Guide

ScenarioRecommendation
Open source projectGitHub Actions
Enterprise with AzureAzure DevOps Pipelines
Docker deploymentMulti-stage build in CI, push to container registry
NuGet libraryBuild → Test → Pack → Push on tag
Database migrationsRun in CI test stage, script for production
Environment promotionSame artifact, different configuration

来源与署名

来源:codewithmukesh/dotnet-claude-kit位于skills/ci-cd提交2330089

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

更多来自 codewithmukesh/dotnet-claude-kit 的技能

Wrap Up

codewithmukesh

在会话结束时把已完成工作、待办任务与经验写入交接文件,并在会话开始时重新载入。

Productivity & Workflow7542个月前更新

Workflow Mastery

codewithmukesh

Claude Code workflow mastery for .NET developers. Covers parallel execution with git worktrees, plan mode strategy, verification loops, auto-formatting hooks, permission setup for dotnet CLI, prompting techniques, subagent patterns, and context discipline — token budget management, MCP-first navigation, lazy loading, and subagent isolation — all adapted for the .NET ecosystem. Load this skill when setting up Claude Code for a .NET project, optimizing workflows, running parallel sessions, when context is running low or sessions feel sluggish, when exploring a large codebase efficiently, or when the user mentions "productivity", "workflow", "parallel", "worktree", "plan mode", "permissions", "hooks", "10x", "setup Claude Code", "speed up development", "context", "tokens", "budget", "running out of context", "too many files", or "large codebase". Inspired by tips from Boris Cherny (creator of Claude Code) and the Anthropic team.

待分类7542个月前更新

Vertical Slice

codewithmukesh

指导 .NET 开发者采用垂直切片架构组织应用,涵盖功能文件夹、端点分组与处理程序模式。

Software Development7542个月前更新

Testing

codewithmukesh

Testing strategy for .NET 10 applications. Covers xUnit v3, WebApplicationFactory for integration tests, Testcontainers for real database testing, Verify for snapshot testing, and the AAA pattern. Load this skill when writing tests, setting up test infrastructure, reviewing test coverage, or when the user mentions "test", "xUnit", "WebApplicationFactory", "Testcontainers", "integration test", "unit test", "bUnit", "snapshot test", "Verify", "test coverage", "AAA pattern", "WireMock", or "FakeTimeProvider".

待分类7542个月前更新

Tdd

codewithmukesh

Guided test-driven development workflow for .NET 10 using xUnit v3, WebApplicationFactory, Testcontainers, and Verify snapshots. Follows the strict red-green-refactor cycle. Use when: "TDD", "test-driven", "let's TDD this", "red green refactor", "write the test first", or when building a feature with clear acceptance criteria.

待分类7542个月前更新

Spec

codewithmukesh

通过结构化提问,把模糊的功能想法转化为双方确认并持久化的规格说明文件。

Productivity & Workflow7542个月前更新