conocimientocicd-architecttemplates/6787 B
azure-pipelines.nettool.yml.template
Fichero que /hv:cicd-architect usa o materializa en el proyecto. Se muestra tal cual está en el plugin.
# =============================================================================
# {{PROJECT_NAME}} - CI + publicacion NuGet (dotnet tool / libreria)
# Ovillo cicd-architect nettool @ {{TEMPLATE_STAMP}} (sello de plantilla; /cicd-status detecta drift)
# -----------------------------------------------------------------------------
# Plantilla Ovillo cicd-architect - Variante C (stack .NET-tool / CLI / libreria)
# Cumple G1-G19 de cicd-runtime.md. Validado en una libreria interna piloto.
#
# NO es una web: el entregable es un .nupkg publicado al feed interno de la organización.
# Un solo stage (el pool configurado + agente de build): el agente de build y la share son la misma
# maquina -> publicar es Copy-Item local; ademas evita el bug SSL de descarga de
# artefactos entre stages en Azure DevOps Server 2020 (R3).
#
# Prerrequisito de infra (pedir al equipo de infraestructura 1 vez, analogo al permiso Use de
# el pool configurado - TEC-003): la cuenta de servicio del agente de build necesita
# ESCRITURA NTFS sobre la share del feed (sustituye la capability DeployTarget).
#
# Gate de seguridad R22: opcional para paquetes. El scan de deps/SAST puede
# correr como informe en el Build, pero NO hay stage de deploy que bloquear.
# =============================================================================
name: $(date:yyyyMMdd)$(rev:.r)
trigger:
branches:
include:
- {{RAMA_BASE}} # CI en cada push (R21: derivar de branching.estrategia)
tags:
include:
- 'v*' # tag v* dispara la publicacion del .nupkg al feed
paths:
include:
- 'src/**' # top-level (R7)
- 'src/**/*' # subdirectorios profundos (workaround R7)
- 'ops/testing/**'
- 'ops/testing/**/*'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- 'global.json'
- '{{SLN_OR_SLNX}}'
- 'azure-pipelines.yml'
pr: none # R21: PR triggers se gestionan por branch policy (UI), no en YAML
variables:
buildConfiguration: 'Release'
solution: '{{SLN_OR_SLNX}}'
packProject: '{{PACK_CSPROJ_PATH}}'
nupkgOutputDir: '{{PACKAGE_OUTPUT_DIR}}'
nugetShare: '\\fileserver\Repositorio\MyOrg\PaquetesNuget'
coverageLineThreshold: {{COVERAGE_LINE_THRESHOLD}}
coverageBranchThreshold: {{COVERAGE_BRANCH_THRESHOLD}}
stages:
- stage: BuildTestPublish
displayName: 'Build - Test - (Publish en tags)'
jobs:
- job: Pipeline
displayName: 'CI + publicacion NuGet'
pool:
name: {{BUILD_POOL}} # R1: automation pool server-wide
demands:
- Agent.ComputerName -equals {{BUILD_AGENT}} # R1: agente de build = host de la share
steps:
- checkout: self
- task: UseDotNet@2 # R4: version canonica
displayName: 'Asegurar .NET SDK'
inputs:
packageType: sdk
version: '{{SDK_VERSION}}'
includePreviewVersions: true
- task: DotNetCoreCLI@2 # R4
displayName: 'Restore'
inputs:
command: restore
projects: '$(solution)'
- task: DotNetCoreCLI@2 # R4
displayName: 'Build (Release, TreatWarningsAsErrors)'
inputs:
command: build
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration) --no-restore'
# G7 (R18): gate de cobertura WARN-first con el script propio del repo (ops/cicd/scripts/coverage-gate.ps1,
# materializado por /cicd-init). Sin herramientas externas ni feeds. -Mode block para que bloquee.
- task: PowerShell@2
displayName: 'Coverage gate line>=70/branch>=60 (G7, WARN)'
condition: succeededOrFailed()
inputs:
targetType: filePath
filePath: '$(Build.SourcesDirectory)/ops/cicd/scripts/coverage-gate.ps1'
arguments: '-Path "$(Agent.TempDirectory)/coverage" -ThresholdLine 70 -ThresholdBranch 60 -Mode warn'
- task: PublishCodeCoverageResults@1 # R4: @1 con Cobertura (no @2)
displayName: 'Publicar cobertura (Cobertura)'
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Agent.TempDirectory)/coverage/**/coverage.cobertura.xml'
reportDirectory: '$(Build.ArtifactStagingDirectory)/coverage-report'
- task: PublishBuildArtifacts@1 # R4
displayName: 'Publicar reporte HTML'
condition: succeededOrFailed()
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/coverage-report'
ArtifactName: 'CoverageReport'
# build#65: usar 'dotnet pack' por PowerShell, NUNCA el task DotNetCoreCLI@2 con
# command:'pack' -> fuerza --output $(Build.ArtifactStagingDirectory) e IGNORA
# <PackageOutputPath> del .csproj (piloto nettool, build #65: el .nupkg no aparecia
# en nupkgOutputDir y la publicacion fallaba). Ver azure-devops-server-2020-quick-ref.md.
- powershell: |
$ErrorActionPreference = 'Stop'
dotnet pack "$(packProject)" --configuration $(buildConfiguration) --no-build
if ($LASTEXITCODE -ne 0) { throw "dotnet pack fallo (exit $LASTEXITCODE)" }
displayName: 'Pack (solo en tags v*)'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))
- powershell: |
$ErrorActionPreference = 'Stop'
$pkg = Get-ChildItem '$(nupkgOutputDir)' -Filter '*.nupkg' -ErrorAction Stop |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $pkg) { throw "No se encontro ningun .nupkg en $(nupkgOutputDir)" }
$dest = '$(nugetShare)'
if (-not (Test-Path $dest)) { throw "Share no accesible: $dest (permisos NTFS del agente - pedir al equipo de infraestructura)" }
$target = Join-Path $dest $pkg.Name
if (Test-Path $target) {
throw "Ya existe '$($pkg.Name)' en la share. Las versiones NuGet son inmutables: " +
"sube <Version> en el .csproj y vuelve a taggear."
}
Copy-Item -Path $pkg.FullName -Destination $target -Force
Write-Host "##[section]Publicado $($pkg.Name) en $dest"
displayName: 'Publicar .nupkg en la share (solo en tags v*)'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))