conocimientocicd-architecttemplates/12.947 B
azure-pipelines.fase2.console.yml.template
Fichero que /hv:cicd-architect usa o materializa en el proyecto. Se muestra tal cual está en el plugin.
# =============================================================================
# {{PROYECTO_NOMBRE}} — Pipeline CI + CD (Fase 2, stack .NET Console/Worker)
# Ovillo cicd-architect console @ {{TEMPLATE_STAMP}} (sello de plantilla; /cicd-status detecta drift)
# Reglas: .claude/skills/cicd-runtime/SKILL.md (G1-G19; CD de Console/Worker = R25 ampliada)
# Limitaciones Azure DevOps Server 2020: .claude/skills/cicd-architect/references/azure-devops-server-2020-quick-ref.md
#
# QUE ES: pipeline para un entrypoint Console/Worker (sync periodico, batch, BackgroundService).
# CD via TAREA PROGRAMADA (mecanismo por defecto): proceso fresco por ejecucion -> deploy =
# file-sync (sin locks entre runs). Para workers always-on (IHostedService corriendo siempre) el
# deploy seria un Windows Service (variante 'sc stop/start', PENDIENTE: steps/deploy-windows-service.yml
# se anadira cuando un proyecto lo pida; de momento solo Tarea Programada).
#
# RAMAS CONDICIONALES que /cicd-init aplica (igual que fase2.dotnet):
# (a) SIN proyecto de test -> ELIMINAR 'dotnet test' + coverage + gate R18.
# (b) Config por entorno (.NET SDK-style sin Key Vault): {{CONFIG_INJECT_STEP}} en el step de deploy
# (steps/deploy-scheduled-task.yml) inyecta los secretos del VG en appsettings.json (R23).
# =============================================================================
name: $(date:yyyyMMdd)$(rev:.r)
trigger:
# R21: ramas segun configuracion.branching.estrategia (igual que fase2.dotnet)
branches:
include:
- {{RAMA_BASE}}
# {{TRIGGER_BRANCHES_EXTRA}} <- /cicd-init R21
paths:
# R7: doble patron Azure DevOps Server 2020 + acotado al subarbol del entrypoint Console (R25)
include:
- '{{ENTRYPOINT_PATH}}/**'
- '{{ENTRYPOINT_PATH}}/**/*'
- 'ops/testing/**'
- 'ops/testing/**/*'
- 'azure-pipelines.{{SLUG}}.yml'
pr: none
variables:
- group: {{PIPELINE_NAME}}-secrets # R16
- name: BuildConfiguration
value: 'Release'
- name: solutionPath
value: '{{SLN_PATH}}'
- name: consoleProject
value: '{{CONSOLE_CSPROJ}}' # el .csproj del entrypoint Console/Worker
- name: testProject
value: '{{TESTS_CSPROJ}}'
- name: coverageLineThreshold
value: '70'
- name: coverageBranchThreshold
value: '60'
# ── CD Console (R25): task programada ──────────────────────────────
- name: taskName
value: '{{TASK_NAME}}' # ej. MyCompany.Billing.Sync
- name: deployFolder
value: '{{DEPLOY_FOLDER}}' # ej. D:\Apps\Billing (carpeta destino en el servidor)
- name: consoleExe
value: '{{CONSOLE_EXE}}' # ej. MyCompany.Billing.Console.exe
- name: taskScheduleArgs
value: '{{TASK_SCHEDULE_ARGS}}' # ej. '/SC HOURLY' o '/SC DAILY /ST 02:00'
- name: taskRunAccount
value: '{{TASK_RUN_ACCOUNT}}' # R6: 'NT AUTHORITY\SYSTEM' por defecto
- name: backupRoot
value: 'C:\Backups' # R15
# {{QUALITY_SYNC_VARS}} <- /cicd-init FASE 2.7 (igual que fase2.dotnet)
stages:
# ───────────────────────────────────────────────────────────────────────
# STAGE 1: BUILD (auto) — identico criterio que fase2.dotnet
# ───────────────────────────────────────────────────────────────────────
- stage: Build
displayName: 'Build & Test'
jobs:
- job: BuildAndTest
pool:
name: {{BUILD_POOL}} # R1
demands:
- Agent.ComputerName -equals {{BUILD_AGENT}} # R1
timeoutInMinutes: 30
steps:
- task: PowerShell@2
displayName: 'Fail-fast: validar VG secretos' # R16
inputs:
targetType: inline
script: |
try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13 } catch { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 }
$required = @({{LISTA_SECRETOS_VG}})
$missing = $required | Where-Object { [string]::IsNullOrWhiteSpace((Get-Item "env:$_" -EA SilentlyContinue).Value) }
if ($missing.Count -gt 0) { Write-Error "Secretos vacios: $($missing -join ', '). Rellenar en VG '{{PIPELINE_NAME}}-secrets'."; exit 1 }
- task: UseDotNet@2 # R4
displayName: 'Install .NET SDK {{NET_VERSION}}'
inputs:
packageType: 'sdk'
version: '{{NET_VERSION}}.x'
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: 'restore'
projects: '$(solutionPath)'
feedsToUse: 'config'
nugetConfigPath: '{{NUGET_CONFIG_PATH}}'
- task: DotNetCoreCLI@2
displayName: 'dotnet build (Release)'
inputs:
command: 'build'
projects: '$(solutionPath)'
arguments: '--configuration $(BuildConfiguration) --no-restore'
# HALLAZGO H: limpiar cobertura/opencover obsoletos del temp del agente
- task: PowerShell@2
displayName: 'Limpiar cobertura/opencover obsoletos (HALLAZGO H)'
inputs:
targetType: inline
script: |
Get-ChildItem $env:AGENT_TEMPDIRECTORY -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like '*cobertura.xml' -or $_.Name -like '*opencover.xml' } |
Remove-Item -Force -ErrorAction SilentlyContinue
# BLOQUE OMITIBLE (sin tests -> /cicd-init elimina test+coverage+R18)
- task: DotNetCoreCLI@2
displayName: 'dotnet test (solucion completa, with coverage)'
inputs:
command: 'test'
projects: '$(solutionPath)'
arguments: '--configuration $(BuildConfiguration) --no-build{{TEST_FILTER}} --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover'
- task: PublishCodeCoverageResults@1 # R4 NO @2
displayName: 'Publish coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/*cobertura.xml'
# G7 (R18): gate de cobertura WARN-first (steps/coverage-gate.yml -> ops/cicd/scripts/coverage-gate.ps1). Identico a fase2.dotnet.
# {{R18_COVERAGE_GATE}} <- /cicd-init materializa aqui el step 'Coverage gate ... (R18, WARN)' de fase2.dotnet
# (`- template: steps/coverage-gate.yml` con los thresholds del pipeline). Si no hay tests, se elimina.
# R22: gate de ciberseguridad (verdict-file). El code del Console puede tener CVEs/secretos.
- template: steps/security-scan-build.yml
parameters:
stack: dotnet
- task: DotNetCoreCLI@2
displayName: 'dotnet publish (Console/Worker)'
inputs:
command: 'publish'
projects: '$(consoleProject)'
publishWebProjects: false # NO es web
arguments: '--configuration $(BuildConfiguration) --no-build --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: false # el deploy hace file-sync de la carpeta, no de un zip
- task: PublishBuildArtifacts@1
displayName: 'Publish artifact drop'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
# ───────────────────────────────────────────────────────────────────────
# STAGE 2: DEPLOY DEV (on-demand) — Tarea Programada
# ───────────────────────────────────────────────────────────────────────
- stage: DeployDev
displayName: 'Deploy a DEV (on-demand, task programada)'
dependsOn: Build
condition: and(succeeded(), eq(variables['DeployEnv'], 'dev')) # R20
jobs:
- job: DeployToDev
pool:
name: {{BUILD_POOL}}
demands:
- DeployTarget -equals {{CONSOLE_DEPLOY_DEMAND_DEV}} # R1/R25/FB-002: demand REAL del pool (derivado por /cicd-init)
timeoutInMinutes: 20
steps:
- template: steps/deploy-scheduled-task.yml
parameters:
mode: warn # R22 DEV = WARN
# ───────────────────────────────────────────────────────────────────────
# STAGE 3: DEPLOY DEMO/Pre (on-demand) — Tarea Programada
# ───────────────────────────────────────────────────────────────────────
- stage: DeployDemo
displayName: 'Deploy a DEMO/Pre (on-demand, task programada)'
dependsOn: Build
condition: and(succeeded(), eq(variables['DeployEnv'], 'pre')) # R20 (sin ManualValidation; el gate es DeployEnv + /cicd-deploy)
jobs:
- job: DeployToDemo
pool:
name: {{BUILD_POOL}}
demands:
- DeployTarget -equals {{CONSOLE_DEPLOY_DEMAND_PRE}}
timeoutInMinutes: 30
steps:
- template: steps/deploy-scheduled-task.yml
parameters:
mode: block # R22 DEMO/Pre = BLOCK
# ───────────────────────────────────────────────────────────────────────
# STAGE 4: DEPLOY PROD (on-demand) — Tarea Programada [PLACEHOLDER]
# ───────────────────────────────────────────────────────────────────────
# TEC-006: PROD como `job` normal (demands solo en runtime), NO `deployment`+environment mientras
# sea placeholder. Al aprovisionar PROD: crear Environment SIN PUNTOS ('{{PROYECTO_SLUG}}Prod') +
# grupo aprobador >=2 + convertir a `deployment`. Console/Worker normalmente es 1 nodo (no rolling).
- stage: DeployProd
displayName: 'Deploy a PROD (on-demand, task programada) [PLACEHOLDER]'
dependsOn: Build
condition: and(succeeded(), eq(variables['DeployEnv'], 'pro')) # R20
jobs:
- job: DeployToProd
pool:
name: {{BUILD_POOL}}
demands:
- Agent.Name -equals {{PROD_NODE_A}} # R1/R25 (host de batch/svc real; /cicd-init lo deriva del pool)
timeoutInMinutes: 30
steps:
- template: steps/deploy-scheduled-task.yml
parameters:
mode: block # R22 PROD = BLOCK
# =============================================================================
# Placeholders a sustituir por /cicd-init:
# {{PROYECTO_NOMBRE}}, {{PROYECTO_SLUG}}, {{SLUG}}, {{RAMA_BASE}}, {{PIPELINE_NAME}}, {{NET_VERSION}},
# {{SLN_PATH}}, {{CONSOLE_CSPROJ}}, {{TESTS_CSPROJ}}, {{ENTRYPOINT_PATH}}, {{NUGET_CONFIG_PATH}},
# {{LISTA_SECRETOS_VG}}, {{TEMPLATE_STAMP}}, {{TEST_FILTER}}, {{R18_COVERAGE_GATE}},
# {{CONFIG_INJECT_STEP}} (R23, en steps/deploy-scheduled-task.yml),
# {{QUALITY_SYNC_VARS}}, (CD Console:) {{TASK_NAME}}, {{DEPLOY_FOLDER}}, {{CONSOLE_EXE}},
# {{TASK_SCHEDULE_ARGS}}, {{TASK_RUN_ACCOUNT}},
# {{CONSOLE_DEPLOY_DEMAND_DEV/PRE}}, {{PROD_NODE_A}} (demands REALES del pool, FB-002).
#
# Mecanismo: por defecto TAREA PROGRAMADA (steps/deploy-scheduled-task.yml). Para worker
# always-on, /cicd-init puede usar steps/deploy-windows-service.yml (sc stop/start). Ver R25 +
# P-console de /cicd-init. El destino (DeployTarget) se DERIVA del pool real (parametrizable, FB-002):
# Console/Worker no tiene un tipo de servidor fijo -> /cicd-init mapea al valor que reporte el agente.
# =============================================================================