Share via


definição de steps.powershell

A powershell etapa executa um script usando Windows PowerShell (no Windows) ou pwsh (Linux e 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.

Definições que fazem referência a essa definição: etapas

Propriedades

powershell String. Obrigatório como primeira propriedade.
Script embutido do PowerShell.

errorActionPreference String.
A menos que especificado de outra forma, a preferência de ação de erro usa como padrão a parada de valor. Consulte a seguinte seção para obter mais informações.

failOnStderr String.
Falhará na tarefa se a saída for enviada para Stderr?

ignoreLASTEXITCODE String.
Verifique o código de saída final do script para determinar se a etapa foi bem-sucedida?

workingDirectory String.
Inicie o script com este diretório de trabalho.

condition String.
Avalie essa expressão de condição para determinar se essa tarefa deve ser executada.

continueOnErrorbooliano.
Continuar em execução mesmo em caso de falha?

displayName String.
Nome legível para a tarefa.

targetdestino.
Ambiente no qual executar essa tarefa.

enabledbooliano.
Executar essa tarefa quando o trabalho for executado?

env dicionário de cadeia de caracteres.
Variáveis a serem mapeadas para o ambiente do processo.

name String.
ID da etapa. Valores aceitáveis: [-_A-Za-z0-9]*.

timeoutInMinutes String.
Tempo de espera para que essa tarefa seja concluída antes que o servidor a mate.

Observação

Os pipelines podem ser configurados com um tempo limite de nível de trabalho. Se o intervalo de tempo limite do nível do trabalho decorrer antes da conclusão da etapa, o trabalho em execução (incluindo a etapa) será encerrado, mesmo que a etapa esteja configurada com um intervalo mais longo timeoutInMinutes . Para obter mais informações, consulte Tempos limite.

retryCountOnTaskFailure String.
Número de novas tentativas se a tarefa falhar.

Comentários

A palavra-chave powershell é um atalho para a tarefa do PowerShell. A tarefa executa um script usando Windows PowerShell (no Windows) ou pwsh (Linux e macOS).

Cada sessão do PowerShell dura apenas enquanto o trabalho é executado. As tarefas que dependem do que foi inicializado devem estar no mesmo trabalho que a inicialização.

Saiba mais sobre condições e tempos limite.

Preferência de ação de erro

A menos que especificado de outra forma, a preferência de ação de erro usa como padrão o valor stope a linha $ErrorActionPreference = 'stop' é acrescentada à parte superior do script.

Quando a preferência de ação de erro é definida como parada, os erros fazem com que o PowerShell encerre a tarefa e retorne um código de saída diferente de zero. A tarefa também está marcada como Falha.

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

Ignorar o último código de saída

O último código de saída retornado do script é verificado por padrão. Um código diferente de zero indica uma falha de etapa, nesse caso, o sistema acrescenta o script com:

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

Se você não quiser esse comportamento, especifique ignoreLASTEXITCODE: true.

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

Saiba mais sobre condições e tempos limite.

Exemplos

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

Confira também