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 文字列。
この条件式を評価して、このタスクを実行するかどうかを判断します。

continueOnErrorboolean
失敗しても実行を続けますか?

displayName 文字列。
タスクの人間が判読できる名前。

targetターゲット
このタスクを実行する環境。

enabledboolean
ジョブの実行時にこのタスクを実行しますか?

env 文字列ディクショナリ。
プロセスの環境にマップする変数。

name 文字列。
ステップの ID。 使用できる値: [-_A-Za-z0-9]*。

timeoutInMinutes 文字列。
サーバーによって強制終了されるまで、このタスクが完了するまでの時間。

注意

パイプラインは、ジョブ レベルのタイムアウトで構成できます。 ステップが完了する前にジョブ・レベルのタイムアウト間隔が経過すると、ステップが長い timeoutInMinutes 間隔で構成されている場合でも、実行中のジョブ (ステップを含む) が終了します。 詳細については、「 タイムアウト」を参照してください。

retryCountOnTaskFailure 文字列。
タスクが失敗した場合の再試行回数。

注釈

powershell キーワードは、PowerShell タスクのショートカットです。 タスクは、Windows PowerShell (Windows) または pwsh (Linux および macOS) を使用してスクリプトを実行します。

各 PowerShell セッションは、実行されるジョブの期間中のみ継続します。 ブートストラップが行われた内容に依存するタスクは、そのブートストラップと同じジョブ内にある必要があります。

条件タイムアウトの詳細を理解してください。

エラー アクションの基本設定

特に指定しない限り、エラー アクションの基本設定は既定で 値 stopに設定され、行 $ErrorActionPreference = 'stop' はスクリプトの先頭に付加されます。

エラー アクションの基本設定が停止に設定されている場合、エラーにより PowerShell はタスクを終了し、0 以外の終了コードを返します。 タスクも失敗としてマークされます。

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

最後の終了コードを無視する

スクリプトから返された最後の終了コードは、既定でチェックされます。 0 以外のコードはステップが失敗したことを示し、その場合、システムはスクリプトに以下を追加します。

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

関連項目