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

在 session 結束時把已完成工作、待辦事項與經驗寫入交接檔案,並在 session 開始時重新載入。

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 個月前更新