steps.powershell definition

Der powershell Schritt führt ein Skript mit Windows PowerShell (unter Windows) oder pwsh (Linux und macOS) aus.

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.

Definitionen, die auf diese Definition verweisen: Schritte

Eigenschaften

powershell Schnur. Erforderlich als erste Eigenschaft.
PowerShell-Inlineskript.

errorActionPreference Schnur.
Sofern nicht anders angegeben, wird die Fehleraktionseinstellung standardmäßig auf den Wert stop festgelegt. Weitere Informationen finden Sie in folgendem Abschnitt.

failOnStderr Schnur.
Fehler beim Task, wenn die Ausgabe an Stderr gesendet wird?

ignoreLASTEXITCODE Schnur.
Überprüfen Sie den endgültigen Exitcode des Skripts, um festzustellen, ob der Schritt erfolgreich war?

workingDirectory Schnur.
Starten Sie das Skript mit diesem Arbeitsverzeichnis.

condition Schnur.
Bewerten Sie diesen Bedingungsausdruck, um zu bestimmen, ob dieser Task ausgeführt werden soll.

continueOnErrorBoolesch.
Weiterhin ausgeführt, auch bei Einem Fehler?

displayName Schnur.
Lesbarer Name für die Aufgabe.

targettarget.
Umgebung, in der diese Aufgabe ausgeführt werden soll.

enabledBoolesch.
Führen Sie diesen Task aus, wenn der Auftrag ausgeführt wird?

env Zeichenfolgenwörterbuch.
Variablen, die der Umgebung des Prozesses zugeordnet werden sollen.

name Schnur.
ID des Schritts. Zulässige Werte: [-_A-Za-z0-9]*.

timeoutInMinutes Schnur.
Zeit, bis diese Aufgabe abgeschlossen ist, bevor sie vom Server beendet wird.

Hinweis

Pipelines können mit einem Timeout auf Auftragsebene konfiguriert werden. Wenn das Timeoutintervall auf Auftragsebene verstreicht, bevor Der Schritt abgeschlossen ist, wird der ausgeführte Auftrag (einschließlich Ihres Schritts) beendet, auch wenn der Schritt mit einem längeren timeoutInMinutes Intervall konfiguriert ist. Weitere Informationen finden Sie unter Timeouts.

retryCountOnTaskFailure Schnur.
Anzahl der Wiederholungsversuche, wenn die Aufgabe fehlschlägt.

Hinweise

Das powershell-Schlüsselwort ist eine Verknüpfung für die PowerShell-Aufgabe. Der Task führt ein Skript mit Windows PowerShell (unter Windows) oder pwsh (Linux und macOS) aus.

Jede PowerShell-Sitzung bleibt nur für die Dauer des Auftrags, in dem sie ausgeführt wird, bestehen. Vorgänge, die davon abhängen, welches Bootstrapping stattgefunden hat, müssen sich im selben Auftrag wie der Bootstrap befinden.

Erfahren Sie mehr über Bedingungen und Timeouts.

Fehleraktionseinstellung

Sofern nicht anders angegeben, ist die Fehleraktionseinstellung standardmäßig auf den Wert stopfestgelegt, und die Zeile $ErrorActionPreference = 'stop' wird am Anfang des Skripts vorangestellt.

Wenn die Fehleraktionseinstellung auf Beenden festgelegt ist, führen Fehler dazu, dass PowerShell den Task beendet und einen Nichtzero-Exitcode zurückgibt. Die Aufgabe ist auch als Fehler gekennzeichnet.

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

Letzten Exitcode ignorieren

Der letzte von Ihrem Skript zurückgegebene Exitcode wird standardmäßig überprüft. Ein Code ungleich null (0) gibt einen Schrittfehler an. In diesem Fall fügt das System Ihrem Skript Folgendes an:

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

Wenn Sie dieses Verhalten nicht möchten, geben Sie ignoreLASTEXITCODE: true an.

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

Erfahren Sie mehr über Bedingungen und Timeouts.

Beispiele

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

Weitere Informationen