определение steps.powershell

Этот powershell шаг запускает скрипт с помощью Windows PowerShell (в Windows) или pwsh (Linux и 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.

Определения, ссылающиеся на это определение: шаги

Свойства

powershell Строка. Требуется в качестве первого свойства.
Встроенный скрипт PowerShell.

errorActionPreference Строка.
Если не указано иное, параметр действия ошибки по умолчанию имеет значение stop. Дополнительные сведения см. в следующем разделе.

failOnStderr Строка.
Не удается выполнить задачу, если выходные данные отправляются в Stderr?

ignoreLASTEXITCODE Строка.
Проверьте код окончательного завершения скрипта, чтобы определить, выполнен ли шаг успешно?

workingDirectory Строка.
Запустите скрипт с помощью этого рабочего каталога.

condition Строка.
Оцените это выражение условия, чтобы определить, следует ли выполнять эту задачу.

continueOnErrorлогическое значение.
Продолжить работу даже при сбое?

displayName Строка.
Понятное имя задачи.

targetцелевой объект.
Среда, в которой выполняется эта задача.

enabledлогическое значение.
Запускать эту задачу при выполнении задания?

env словарь строк.
Переменные для сопоставления со средой процесса.

name Строка.
Идентификатор шага. Допустимые значения: [-_A-Za-z0-9]*.

timeoutInMinutes Строка.
Время ожидания завершения этой задачи, прежде чем сервер завершит ее.

Примечание

Для конвейеров можно настроить время ожидания на уровне задания. Если интервал времени ожидания на уровне задания истекает до завершения шага, выполняемое задание (включая ваш шаг) завершается, даже если шаг настроен с более длительным timeoutInMinutes интервалом. Дополнительные сведения см. в разделе Время ожидания.

retryCountOnTaskFailure Строка.
Количество повторных попыток в случае сбоя задачи.

Комментарии

Ключевое слово powershell является ярлыком для задачи PowerShell. Задача выполняет скрипт с помощью Windows PowerShell (в Windows) или pwsh (Linux и macOS).

Каждый сеанс PowerShell длится только в течение всего задания, в котором он выполняется. Задачи, зависящие от начальной загрузки, должны находиться в том же задании, что и начальная загрузка.

Дополнительные сведения об условиях и времени ожидания.

Выбор действия ошибки

Если не указано иное, для параметра действия ошибки по умолчанию используется значение stop, а строка $ErrorActionPreference = 'stop' добавляется в начало скрипта.

Если для параметра действия с ошибкой задано значение Stop, ошибки приводят к тому, что PowerShell завершает задачу и возвращает ненулевой код выхода. Задача также помечена как Сбой.

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

Пропустить код последнего выхода

Последний код выхода, возвращенный из скрипта, проверяется по умолчанию. Ненулевой код указывает на сбой шага. В этом случае система добавляет к скрипту:

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

Если такое поведение не требуется, укажите ignoreLASTEXITCODE: true.

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

Дополнительные сведения об условиях и времени ожидания.

Примеры

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

См. также раздел