steps.powershell 定義

此步驟會在 powershell Windows) 上使用 Windows PowerShell (或 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 字串。
除非另有指定,否則錯誤動作喜好設定預設為停止值。 如需詳細資訊,請參閱下一節。

failOnStderr 字串。
如果輸出傳送至 Stderr,工作會失敗?

ignoreLASTEXITCODE 字串。
檢查文本的最終結束代碼,以判斷步驟是否成功?

workingDirectory 字串。
使用此工作目錄啟動文稿。

condition 字串。
評估此條件表達式,以判斷是否要執行這項工作。

continueOnError布爾值
即使在失敗時仍繼續執行?

displayName 字串。
工作的人類可讀取名稱。

targettarget
要在其中執行這項工作的環境。

enabled布爾值
當作業執行時,請執行這項工作?

env 字串字典。
要對應至進程環境的變數。

name 字串。
步驟的標識碼。 可接受的值:[-_A-Za-z0-9]*。

timeoutInMinutes 字串。
等候此工作在伺服器終止之前完成的時間。

注意

管線可以設定為作業層級逾時。 如果作業層級逾時間隔在步驟完成之前經過,則即使步驟已設定較長 timeoutInMinutes 的間隔,執行中作業仍 (包括步驟) 終止。 如需詳細資訊,請參閱 逾時

retryCountOnTaskFailure 字串。
如果工作失敗,重試次數。

備註

powershell關鍵詞是 PowerShell 工作的快捷方式。 此工作會在 Windows) 上使用 Windows PowerShell (或 pwsh (Linux 和 macOS) 來執行腳本。

每個 PowerShell 會話只會在執行作業的持續時間內持續執行。 相依於啟動程式的工作必須與啟動程式位於相同的作業中。

深入了解 條件逾時

錯誤動作喜好設定

除非另有指定,否則錯誤動作喜好設定預設為 值 stop,而且行 $ErrorActionPreference = '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

另請參閱