definición de steps.powershell

El powershell paso ejecuta un script mediante Windows PowerShell (en Windows) o pwsh (Linux y macOS).

steps:
- powershell: string # Required as first property. Inline PowerShell script.
  errorActionPreference: string # Unless otherwise specified, the error action preference defaults to the value stop. See the following section for more information.
  failOnStderr: string # Fail the task if output is sent to Stderr?
  ignoreLASTEXITCODE: string # Check the final exit code of the script to determine whether the step succeeded?
  workingDirectory: string # Start the script with this working directory.
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
  retryCountOnTaskFailure: string # Number of retries if the task fails.
steps:
- powershell: string # Required as first property. Inline PowerShell script.
  errorActionPreference: string # Unless otherwise specified, the error action preference defaults to the value stop. See the following section for more information.
  failOnStderr: string # Fail the task if output is sent to Stderr?
  ignoreLASTEXITCODE: string # Check the final exit code of the script to determine whether the step succeeded?
  workingDirectory: string # Start the script with this working directory.
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
steps:
- powershell: string # Required as first property. Inline PowerShell script.
  errorActionPreference: string # Unless otherwise specified, the error action preference defaults to the value stop. See the following section for more information.
  failOnStderr: string # Fail the task if output is sent to Stderr?
  ignoreLASTEXITCODE: string # Check the final exit code of the script to determine whether the step succeeded?
  workingDirectory: string # Start the script with this working directory.
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.

Definiciones que hacen referencia a esta definición: pasos

Propiedades

powershell Cadena. Obligatorio como primera propiedad.
Script de PowerShell insertado.

errorActionPreference Cadena.
A menos que se especifique lo contrario, la preferencia de acción de error tiene como valor predeterminado detener el valor. Para obtener más información, vea la sección siguiente.

failOnStderr Cadena.
¿Se produce un error en la tarea si la salida se envía a Stderr?

ignoreLASTEXITCODE Cadena.
Compruebe el código de salida final del script para determinar si el paso se realizó correctamente?

workingDirectory Cadena.
Inicie el script con este directorio de trabajo.

condition Cadena.
Evalúe esta expresión de condición para determinar si se va a ejecutar esta tarea.

continueOnErrorbooleano.
¿Sigue ejecutándose incluso en caso de error?

displayName Cadena.
Nombre legible de la tarea.

targettarget.
Entorno en el que se va a ejecutar esta tarea.

enabledbooleano.
¿Ejecuta esta tarea cuando se ejecuta el trabajo?

env diccionario de cadenas.
Variables que se van a asignar al entorno del proceso.

name Cadena.
Id. del paso. Valores aceptables: [-_A-Za-z0-9]*.

timeoutInMinutes Cadena.
Tiempo para esperar a que esta tarea se complete antes de que el servidor la mate.

Nota

Las canalizaciones se pueden configurar con un tiempo de espera de nivel de trabajo. Si el intervalo de tiempo de espera de nivel de trabajo transcurre antes de que se complete el paso, se finaliza el trabajo en ejecución (incluido el paso), incluso si el paso está configurado con un intervalo más largo timeoutInMinutes . Para obtener más información, vea Tiempos de espera.

retryCountOnTaskFailure Cadena.
Número de reintentos si se produce un error en la tarea.

Comentarios

La palabra clave powershell es un acceso directo para la tarea de PowerShell. La tarea ejecuta un script mediante Windows PowerShell (en Windows) o pwsh (Linux y macOS).

Cada sesión de PowerShell solo dura el tiempo que dura el trabajo en el que se ejecuta. Las tareas que dependen de lo que se ha arrancado deben estar en el mismo trabajo que el arranque.

Obtenga más información sobre las condiciones y los tiempos de espera.

Preferencia de acción de error

A menos que se especifique lo contrario, la preferencia de acción de error tiene stopcomo valor predeterminado y la línea $ErrorActionPreference = 'stop' se antepone a la parte superior del script.

Cuando la preferencia de acción de error se establece en detener, los errores hacen que PowerShell finalice la tarea y devuelva un código de salida distinto de cero. La tarea también se marca como Error.

errorActionPreference: stop | continue | silentlyContinue
steps:
- powershell: |
    Write-Error 'Uh oh, an error occurred'
    Write-Host 'Trying again...'
  displayName: Error action preference
  errorActionPreference: continue

Omitir el último código de salida

El último código de salida devuelto del script se comprueba de forma predeterminada. Un código distinto de cero indica un error de paso, en cuyo caso el sistema anexa el script con:

if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }

Si no desea este comportamiento, especifique ignoreLASTEXITCODE: true.

ignoreLASTEXITCODE: boolean
steps:
- powershell: git nosuchcommand
  displayName: Ignore last exit code
  ignoreLASTEXITCODE: true

Obtenga más información sobre las condiciones y los tiempos de espera.

Ejemplos

steps:
- powershell: Write-Host Hello $(name)
  displayName: Say hello
  name: firstStep
  workingDirectory: $(build.sourcesDirectory)
  failOnStderr: true
  env:
    name: Microsoft

Vea también