steps.powershell definition

Krok powershell uruchamia skrypt przy użyciu Windows PowerShell (w systemie Windows) lub pwsh (Linux i 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.

Definicje odwołujące się do tej definicji: kroki

Właściwości

powershell Ciąg. Wymagane jako pierwsza właściwość.
Wbudowany skrypt programu PowerShell.

errorActionPreference Ciąg.
Jeśli nie określono inaczej, preferencja akcji błędu jest domyślnie ustawiona na zatrzymanie wartości. Aby uzyskać więcej informacji, zobacz następującą sekcję.

failOnStderr Ciąg.
Nie można wykonać zadania, jeśli dane wyjściowe są wysyłane do usługi Stderr?

ignoreLASTEXITCODE Ciąg.
Sprawdź końcowy kod zakończenia skryptu, aby określić, czy krok zakończył się pomyślnie?

workingDirectory Ciąg.
Uruchom skrypt za pomocą tego katalogu roboczego.

condition Ciąg.
Oceń to wyrażenie warunku, aby określić, czy należy uruchomić to zadanie.

continueOnErrorwartość logiczna.
Czy kontynuować działanie nawet w przypadku awarii?

displayName Ciąg.
Czytelna dla człowieka nazwa zadania.

targetelement docelowy.
Środowisko, w którym ma zostać uruchomione to zadanie.

enabledwartość logiczna.
Czy uruchamiać to zadanie po uruchomieniu zadania?

env słownik ciągów.
Zmienne do mapowania na środowisko procesu.

name Ciąg.
Identyfikator kroku. Dopuszczalne wartości: [-_A-Za-z0-9]*.

timeoutInMinutes Ciąg.
Czas oczekiwania na ukończenie tego zadania, zanim serwer go zabije.

Uwaga

Potoki można skonfigurować przy użyciu limitu czasu na poziomie zadania. Jeśli interwał limitu czasu na poziomie zadania upłynął przed ukończeniem kroku, zadanie uruchomione (w tym krok) zostanie zakończone, nawet jeśli krok zostanie skonfigurowany z dłuższym timeoutInMinutes interwałem. Aby uzyskać więcej informacji, zobacz Limity czasu.

retryCountOnTaskFailure Ciąg.
Liczba ponownych prób w przypadku niepowodzenia zadania.

Uwagi

Słowo powershell kluczowe to skrót do zadania programu PowerShell. Zadanie uruchamia skrypt przy użyciu Windows PowerShell (w systemie Windows) lub pwsh (Linux i macOS).

Każda sesja programu PowerShell trwa tylko przez czas trwania zadania, w którym jest uruchamiana. Zadania zależne od tego, co zostało uruchomione, muszą znajdować się w tym samym zadaniu co bootstrap.

Dowiedz się więcej na temat warunków i limitów czasu.

Preferencja akcji błędu

Jeśli nie określono inaczej, preferencja akcji błędu jest domyślnie ustawiona na wartość stop, a wiersz $ErrorActionPreference = 'stop' jest prepended na początku skryptu.

Gdy preferencja akcji błędu jest ustawiona na zatrzymanie, błędy powodują zakończenie zadania przez program PowerShell i zwrócenie kodu zakończenia niezerowego. Zadanie jest również oznaczone jako Niepowodzenie.

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

Ignoruj ostatni kod zakończenia

Ostatni kod zakończenia zwrócony ze skryptu jest domyślnie sprawdzany. Kod niezerowy wskazuje błąd kroku, w którym system dołącza skrypt za pomocą polecenia:

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

Jeśli nie chcesz tego zachowania, określ ignoreLASTEXITCODE: truewartość .

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

Dowiedz się więcej na temat warunków i limitów czasu.

Przykłady

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

Zobacz też