steps.powershell-definition

Steget powershell kör ett skript med antingen Windows PowerShell (i Windows) eller pwsh (Linux och 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.

Definitioner som refererar till den här definitionen: steg

Egenskaper

powershell Sträng. Krävs som första egenskap.
Infogat PowerShell-skript.

errorActionPreference Sträng.
Om inget annat anges används värdet för standardinställningen för felåtgärden. Mer information finns i följande avsnitt.

failOnStderr Sträng.
Misslyckas uppgiften om utdata skickas till Stderr?

ignoreLASTEXITCODE Sträng.
Kontrollera skriptets slutliga slutkod för att avgöra om steget lyckades?

workingDirectory Sträng.
Starta skriptet med den här arbetskatalogen.

condition Sträng.
Utvärdera det här villkorsuttrycket för att avgöra om den här aktiviteten ska köras.

continueOnErrorbooleskt värde.
Vill du fortsätta köra även vid fel?

displayName Sträng.
Läsbart namn för uppgiften.

targetmål.
Miljö där den här uppgiften ska köras.

enabledbooleskt värde.
Kör du den här uppgiften när jobbet körs?

env strängordlista.
Variabler som ska mappas till processens miljö.

name Sträng.
ID för steget. Godtagbara värden: [-_A-Za-z0-9]*.

timeoutInMinutes Sträng.
Det är dags att vänta tills den här uppgiften har slutförts innan servern avlöser den.

Anteckning

Pipelines kan konfigureras med en tidsgräns på jobbnivå. Om tidsgränsintervallet på jobbnivå förflutit innan steget slutförs avslutas det pågående jobbet (inklusive steget), även om steget har konfigurerats med ett längre timeoutInMinutes intervall. Mer information finns i Timeouter.

retryCountOnTaskFailure Sträng.
Antal återförsök om aktiviteten misslyckas.

Kommentarer

Nyckelordet powershell är en genväg för PowerShell-aktiviteten. Uppgiften kör ett skript med antingen Windows PowerShell (i Windows) eller pwsh (Linux och macOS).

Varje PowerShell-session varar endast under hela det jobb där den körs. Uppgifter som är beroende av vad som har bootstrapped måste ha samma jobb som bootstrap.

Läs mer om villkor och tidsgränser.

Inställning för felåtgärd

Om inget annat anges anges standardinställningen för felåtgärden till värdet stopoch raden $ErrorActionPreference = 'stop' läggs till överst i skriptet.

När felåtgärdsinställningen är inställd på att stoppas leder fel till att PowerShell avslutar aktiviteten och returnerar en slutkod som inte är noll. Uppgiften markeras också som Misslyckad.

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

Ignorera den senaste slutkoden

Den senaste slutkoden som returneras från skriptet är markerad som standard. En icke-zerokod anger ett stegfel, i vilket fall systemet lägger till skriptet med:

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

Om du inte vill ha det här beteendet anger du ignoreLASTEXITCODE: true.

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

Läs mer om villkor och tidsgränser.

Exempel

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

Se även