definizione steps.powershell
Il passaggio powershell
esegue uno script usando Windows PowerShell (in Windows) o 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.
Definizioni che fanno riferimento a questa definizione: passaggi
Proprietà
powershell
stringa. Obbligatorio come prima proprietà.
script di PowerShell inline.
errorActionPreference
stringa.
Se non diversamente specificato, per impostazione predefinita la preferenza per l'azione di errore corrisponde al valore stop. Per altre informazioni, vedere la sezione seguente.
failOnStderr
stringa.
Non eseguire l'attività se l'output viene inviato a Stderr?
ignoreLASTEXITCODE
stringa.
Controllare il codice di uscita finale dello script per determinare se il passaggio è riuscito?
workingDirectory
stringa.
Avviare lo script con questa directory di lavoro.
condition
stringa.
Valutare questa espressione di condizione per determinare se eseguire questa attività.
displayName
stringa.
nome leggibile per l'attività.
target
destinazione.
Ambiente in cui eseguire questa attività.
env
dizionario di stringhe.
Variabili di cui eseguire il mapping nell'ambiente del processo.
name
stringa.
ID del passaggio. Valori accettabili: [-_A-Za-z0-9]*.
timeoutInMinutes
stringa.
Tempo di attesa per il completamento dell'attività prima che il server lo uccida.
Nota
Le pipeline possono essere configurate con un timeout a livello di processo. Se l'intervallo di timeout a livello di processo è trascorso prima del completamento del passaggio, il processo in esecuzione (incluso il passaggio) viene terminato, anche se il passaggio è configurato con un intervallo di timeoutInMinutes
più lungo. Per altre informazioni, vedere timeout.
retryCountOnTaskFailure
stringa.
Numero di tentativi in caso di errore dell'attività.
Osservazioni:
La parola chiave powershell
è un collegamento per l'attività di PowerShell .
L'attività esegue uno script usando Windows PowerShell (in Windows) o pwsh
(Linux e macOS).
Ogni sessione di PowerShell dura solo per la durata del processo in cui viene eseguita. Le attività che dipendono da ciò che è stato avviato devono trovarsi nello stesso processo del bootstrap.
Altre informazioni sulle condizioni di e i timeout di .
Preferenza dell'azione di errore
Se non diversamente specificato, per impostazione predefinita la preferenza per l'azione di errore corrisponde al valore stop
e la riga $ErrorActionPreference = 'stop'
viene anteporta all'inizio dello script.
Quando la preferenza per l'azione di errore è impostata su arresta, gli errori causano l'interruzione dell'attività e restituiscono un codice di uscita diverso da zero. L'attività viene contrassegnata anche come Non riuscita.
errorActionPreference: stop | continue | silentlyContinue
steps:
- powershell: |
Write-Error 'Uh oh, an error occurred'
Write-Host 'Trying again...'
displayName: Error action preference
errorActionPreference: continue
Ignorare l'ultimo codice di uscita
L'ultimo codice di uscita restituito dallo script viene controllato per impostazione predefinita. Un codice diverso da zero indica un errore di passaggio, nel qual caso il sistema aggiunge lo script con:
if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }
Se non si desidera questo comportamento, specificare ignoreLASTEXITCODE: true
.
ignoreLASTEXITCODE: boolean
steps:
- powershell: git nosuchcommand
displayName: Ignore last exit code
ignoreLASTEXITCODE: true
Altre informazioni sulle condizioni di e i timeout di .
Esempi
steps:
- powershell: Write-Host Hello $Env:name
displayName: Say hello
name: firstStep
workingDirectory: $(build.sourcesDirectory)
failOnStderr: true
env:
name: Microsoft
Vedere anche
- 'attività di PowerShell
- Altre informazioni sulle condizioni di e timeout