définition steps.powershell

L’étape powershell exécute un script à l’aide de Windows PowerShell (sur Windows) ou pwsh (Linux et 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.

Définitions qui font référence à cette définition : étapes

Propriétés

powershell String. Obligatoire comme première propriété.
Script PowerShell inline.

errorActionPreference String.
Sauf indication contraire, la préférence d’action d’erreur correspond par défaut à la valeur stop. Pour plus d'informations, consultez la section suivante.

failOnStderr String.
Échec de la tâche si la sortie est envoyée à Stderr ?

ignoreLASTEXITCODE String.
Vérifiez le code de sortie final du script pour déterminer si l’étape a réussi ?

workingDirectory String.
Démarrez le script avec ce répertoire de travail.

condition String.
Évaluez cette expression de condition pour déterminer s’il faut exécuter cette tâche.

continueOnErrorbooléen.
Continuez à exécuter même en cas d’échec ?

displayName String.
Nom lisible par l’homme pour la tâche.

targetcible.
Environnement dans lequel exécuter cette tâche.

enabledbooléen.
Exécuter cette tâche lors de l’exécution du travail ?

env dictionnaire de chaînes.
Variables à mapper dans l’environnement du processus.

name String.
ID de l’étape. Valeurs acceptables : [-_A-Za-z0-9]*.

timeoutInMinutes String.
Délai d’attente de la fin de cette tâche avant que le serveur ne la tue.

Notes

Les pipelines peuvent être configurés avec un délai d’expiration au niveau du travail. Si l’intervalle de délai d’attente au niveau du travail s’écoule avant la fin de votre étape, le travail en cours d’exécution (y compris votre étape) est arrêté, même si l’étape est configurée avec un intervalle plus long timeoutInMinutes . Pour plus d’informations, consultez Délais d’expiration.

retryCountOnTaskFailure String.
Nombre de nouvelles tentatives si la tâche échoue.

Remarques

Le powershell mot clé est un raccourci pour la tâche PowerShell. La tâche exécute un script à l’aide de Windows PowerShell (sur Windows) ou pwsh (Linux et macOS).

Chaque session PowerShell existe uniquement pendant la durée du travail dans lequel elle s’exécute. Les tâches qui dépendent de ce qui a été démarré doivent se trouver dans le même travail que le bootstrap.

En savoir plus sur les conditions et les délais d’expiration.

Préférence d’action d’erreur

Sauf indication contraire, la préférence d’action d’erreur correspond par défaut à la valeur stop, et la ligne $ErrorActionPreference = 'stop' est ajoutée en haut de votre script.

Lorsque la préférence d’action d’erreur est définie pour s’arrêter, les erreurs entraînent l’arrêt de la tâche par PowerShell et le retour d’un code de sortie différent de zéro. La tâche est également marquée comme ayant échoué.

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

Ignorer le dernier code de sortie

Le dernier code de sortie retourné par votre script est vérifié par défaut. Un code différent de zéro indique un échec d’étape, auquel cas le système ajoute votre script avec :

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

Si vous ne souhaitez pas ce comportement, spécifiez ignoreLASTEXITCODE: true.

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

En savoir plus sur les conditions et les délais d’expiration.

Exemples

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

Voir aussi