steps.powershell – definice

Krok powershell spustí skript pomocí Windows PowerShell (ve Windows) nebo pwsh (Linux a 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.

Definice, které odkazují na tuto definici: kroky

Vlastnosti

powershell Řetězec. Povinný argument jako první vlastnost.
Vložený skript PowerShellu.

errorActionPreference Řetězec.
Pokud není uvedeno jinak, předvolba chybové akce se ve výchozím nastavení nastaví na hodnotu stop. Další informace naleznete v následující části.

failOnStderr Řetězec.
Pokud se výstup odešle do Stderru, úloha se nezdaří?

ignoreLASTEXITCODE Řetězec.
Zkontrolujte konečný ukončovací kód skriptu a zjistěte, jestli byl krok úspěšný.

workingDirectory Řetězec.
Spusťte skript s tímto pracovním adresářem.

condition Řetězec.
Vyhodnoťte tento výraz podmínky a určete, jestli se má tato úloha spustit.

continueOnErrorboolean.
Chcete pokračovat v provozu i při selhání?

displayName Řetězec.
Název úkolu čitelný pro člověka.

targetcíl.
Prostředí, ve kterém se má tato úloha spustit.

enabledboolean.
Spustit tuto úlohu při spuštění úlohy?

env řetězcový slovník.
Proměnné, které se mají mapovat na prostředí procesu.

name Řetězec.
ID kroku. Přijatelné hodnoty: [-_A-Za-z0-9]*.

timeoutInMinutes Řetězec.
Je čas počkat na dokončení této úlohy, než ho server ukončí.

Poznámka

Kanály mohou být nakonfigurované s vypršením časového limitu na úrovni úlohy. Pokud interval časového limitu na úrovni úlohy uplynou před dokončením kroku, spuštěná úloha (včetně vašeho kroku) se ukončí, a to i v případě, že je krok nakonfigurovaný s delším timeoutInMinutes intervalem. Další informace najdete v tématu Vypršení časových limitů.

retryCountOnTaskFailure Řetězec.
Počet opakování v případě selhání úkolu

Poznámky

Klíčové powershell slovo je zástupce úlohy PowerShellu. Úloha spustí skript pomocí Windows PowerShell (ve Windows) nebo pwsh (Linux a macOS).

Každá relace PowerShellu trvá jenom po dobu trvání úlohy, ve které se spouští. Úlohy, které závisí na tom, co bylo spuštěno, musí být ve stejné úloze jako bootstrap.

Přečtěte si další informace o podmínkách a časových limitech.

Předvolba akce chyby

Pokud není uvedeno jinak, předvolba chybové akce se nastaví jako výchozí na hodnotu stopa řádek $ErrorActionPreference = 'stop' je předsunut na začátek skriptu.

Pokud je předvolba akce chyby nastavená na zastavit, chyby způsobí, že PowerShell ukončí úlohu a vrátí nenulový ukončovací kód. Úkol je také označen jako neúspěšný.

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

Ignorovat poslední ukončovací kód

Ve výchozím nastavení se zkontroluje poslední ukončovací kód vrácený z vašeho skriptu. Nenulový kód označuje selhání kroku. V takovém případě systém připojí váš skript pomocí:

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

Pokud toto chování nechcete, zadejte ignoreLASTEXITCODE: true.

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

Přečtěte si další informace o podmínkách a časových limitech.

Příklady

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

Viz také