Está en la página 1de 30

Azure DevOps YAML

No más cajitas
Luis Fraile
Luis Fraile
CTO b!Play – DevOps Consultant Plain Concepts
Working to make the best promotional platform with digital
rewards at b!Play.

Helping companies to better deliver software and making


software development teams life easier.

Casually Microsoft MVP …

@lfraile
lfraile@plainconcepts.com
lfraile@bhubplay.com
Que vamos a ver 1. Azure Pipelines ¿qué son?

2. Cuál es su flujo básico

3. ¿Qué infraestructura necesitamos?

4. Estructura básica

5. YAML para CI

6. YAML para CD

#HashtagEvento 3
Azure Pipelines
Cloud-hosted pipelines for Linux, Windows and
macOS, with unlimited minutes for open source
Any language, any platform, any cloud
Build, test, and deploy Node.js, Python, Java, PHP, Ruby,
C/C++, .NET, Android, and iOS apps. Run in parallel on
Linux, macOS, and Windows. Deploy to Azure, AWS, GCP
or on-premises

Extensible
Explore and implement a wide range of community-built
build, test, and deployment tasks, along with hundreds of
extensions from Slack to SonarCloud. Support for YAML,
reporting and more

Containers and Kubernetes


Easily build and push images to container registries like Docker
Hub and Azure Container Registry. Deploy containers to
individual hosts or Kubernetes.

Github integration
Ensure fast continuous integration/continuous delivery (CI/CD)
pipelines for every open source project. Get unlimited build
minutes for all open source projects with up to 10 free parallel
jobs across Linux, macOS and Windows

 https://azure.com/pipelines
Flujo básico

Publicación
Instalación Ejecución artefactos
Obtener Despliegue n
herramientas tareas necesarios
fuentes entornos
adicionales compilación (app,
plantillas,…)
Fundamentos de pipelines
Pipeline Stage A
Agente Triggers Variables Job 1
Step 1.1
Step 1.2
...
Job 2
Jobs Tareas Recursos Step 2.1
Step 2.2
...
Stage B
Analíticas ...
YAML: YAML Ain't Markup Language

Nuevo lenguaje de definición de los pipelines

Mejoras
• Versionado en el repositorio
• Reutilización
• Plantillas
Actualmente (28 septiembre) en release solo para CI. Preview para CD

Es el camino a seguir
Agentes Build (y release)
• Son los que se encargan de ejecutar los trabajos
• Definen Capabilities
• Varias opciones Hosted:
– Visual Studio 2019 Preview on Windows Server 2019 (windows-2019)
– Visual Studio 2017 on Windows Server 2016 (vs2017-win2016)
– Visual Studio 2015 on Windows Server 2012R2 (vs2015-win2012r2)
– Windows Server 1803 (win1803) - for running Windows containers
– macOS X Mojave 10.14 (macOS-10.14)
– macOS X High Sierra 10.13 (macOS-10.13)
– Ubuntu 16.04 (ubuntu-16.04)
Agentes self-hosted
• Agentes que instalamos y mantenemos nosotros
• Ajustados a nuestras propias necesidades
– Red
– Software
– Configuración

• Varios agentes por máquina


Agentes Docker (self-hosted)
docker run –d \
-e VSTS_ACCOUNT=lfrailepublic \
-e VSTS_TOKEN=******** \
-e VSTS_POOL=DockerPenguins \
-it mcr.microsoft.com/azure-pipelines/vsts-agent

Imagen en Docker hub


https://hub.docker.com/_/microsoft-azure-pipelines-vsts-agent

Instrucciones para imagen personalizada


https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops
Agentes … modo facturación
• Modelo de facturación
– Trabajos paralelos
– 1800 minutos mensuales gratis en Hosted Agent
– Minutos ilimitados para proyectos Open Source
Triggers
¿Cuándo se lanzará la
compilación?

Programadas Push Pull Request Manuales


Jobs de pipelines - job: string # name of the job, A-Z, a-z,
0-9, and underscore
displayName: string # friendly name to
display in the UI
dependsOn: string | [ string ]
• Agrupan tareas condition: string
strategy:
parallel: # parallel strategy
matrix: # matrix strategy
maxParallel: number # maximum number
• De 1 a n Jobs (habitualmente 1) simultaneous matrix legs to run
# note: `parallel` and `matrix` are
mutually exclusive
# you may specify one or the other;
including both is an error
• Se ejecutan completos en 1 agente # `maxParallel` is only valid with
`matrix`
continueOnError: boolean # 'true' if
future jobs should run even if this job
fails; defaults to 'false'
• Definición opcional pool: pool # see pool schema
workspace:
clean: outputs | resources | all # what
to clean up before the job runs
container: containerReference # container
to run this job inside
timeoutInMinutes: number # how long to run
the job before automatically cancelling
cancelTimeoutInMinutes: number # how much
time to give 'run always even if cancelled
tasks' before killing them
variables: { string: string } | [ variable
| variableReference ]
steps: [ script | bash | pwsh | powershell
| checkout | task | templateReference ]
services: { string: string | container } #
container resources to run as a service
container
Definición de variables
• Valores a reusar en tareas/jobs
• Se pueden definir para sobreescribir durante la ejecución
• Pueden definirse valores secretos
• Sintáxis de uso en tareas
– $(nombre_variable)

• En ejecución se comportan como variables de entorno


– Muy útil en escenarios Docker

• Posibilidad de variables secretas


• Azure KeyVault

14
Variables predefinidas
• Variables internas del propio sistema
• Proporcionan información acerca del pipeline y su ejecución
– P.ej.: Build.SourcesDirectory
• Se pueden usar en las tareas y scripts
– $(nombre_variable)

• Dependen de Builds / Releases


• Listado
– https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variabl
es?view=azure-devops&tabs=yaml

• System.debug nuestra mejor amiga en caso de fallos


15
Tareas
steps:
• Ejecutan trabajos - bash: echo hola

• Muchas ya en Azure DevOps - task: UseDotNet@2


displayName: 'install dotnet sdk'

• Marketplace de Visual Studio inputs:


packageType: 'sdk'
• SDK para crear las nuestras propias version: '3.0.100-rc1-014190'
includePreviewVersions: true
• Plain’ol Scripts - task: DotNetCoreCLI@2
displayName: 'dotnet restore'
– Cmd inputs:
command: restore
– Powershell projects: '$(solution)'
- task: DotNetCoreCLI@2
– Bash displayName: 'dotnet build'
inputs:
command: build
arguments: '--configuration $(buildConfiguration)'
projects: '$(solution)'
Visual Studio Marketplace
https://marketplace.visualstudio.com/
Plantillas YAML
- job: Windows

• Reutilización de definiciones pool:


vmImage: 'vs2017-win2016'
steps:

• Parámetros para personalizar


- script: echo This script runs before the template's steps, only on Windows.
- template: templates/npm-steps.yml # Template reference
parameters:
workDir: ‘./clientApp’
• En el mismo u otro repositorio - script: echo This step runs after the template's steps.

#####################################
• Varios niveles de definición: # template definition
parameters:
workDir: ‘’
– Jobs steps:
- task: Npm@1
inputs:
– Steps command: 'install'
workingDir: ‘${{ parameters.workDir }}’
Recursos externos

Repositorios Contenedore
externos s
(plantillas) • Tests
• compose
Ejemplo YAML
trigger: packageType: 'sdk'
branches: version: '3.0.100-rc1-014190'
include: includePreviewVersions: true
- master
paths: - task: DotNetCoreCLI@2
include: displayName: 'dotnet restore'
- src/* inputs:
- tests/* command: restore
pool: projects: '**/Esquio.sln’
name: Hosted Ubuntu 1604
   - task: DotNetCoreCLI@2
variables: displayName: 'dotnet build'
solution: '**/*.sln' inputs:
buildPlatform: 'Any CPU' command: build
buildConfiguration: 'Release’ arguments: '--configuration $
(buildConfiguration) --no-restore'
steps: projects: '**/Esquio.sln'
- task: UseDotNet@2  
displayName: 'install dotnet sdk'
inputs:

http://bit.ly/yaml_pipelines
¿Y mis cajitas existentes?
• Es posible migrar Builds existentes
manualmente.
• En todos los pasos de las
definiciones visuales botón yaml
• Nos proporciona una ayuda base
para migrar
– Los jobs

– Las tareas

• No todo se puede exportar, p.ej.:


– Variables

– Parámetros
Analíticas
Gestión de resultados
Let’s Build it up
Despliegues
Desplegando
Anatomía general despliegues
Origen de
Disparador Stages de 1 a n
artefactos

Políticas de
Pprogramada CD Builds Repos Release gates Jobs (y pasos)
aprobación

27
Preview de YAML en CD
• Realmente es una preview del nuevo UI (el YAML de CI/CD está activado)
• Nuevos conceptos YAML:
– Stages
– Environment
– Deployment (en vez de job)
• Añade vistas
– Pipelines
– Environments
Let’s YAML
¡GRACIAS!
@lfraile
lfraile@plainconcepts.com
lfraile@bhubplay.com

También podría gustarte