Bagikan melalui


definisi steps.powershell

Langkah ini powershell menjalankan skrip menggunakan Windows PowerShell (di Windows) atau pwsh (Linux dan 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.

Definisi yang mereferensikan definisi ini: langkah-langkah

Properti

powershell String. Diperlukan sebagai properti pertama.
Skrip PowerShell sebaris.

errorActionPreference String.
Kecuali ditentukan lain, preferensi tindakan kesalahan default ke nilai berhenti. Lihat bagian berikut untuk informasi selengkapnya.

failOnStderr String.
Gagalkan tugas jika output dikirim ke Stderr?

ignoreLASTEXITCODE String.
Periksa kode keluar akhir skrip untuk menentukan apakah langkah berhasil?

workingDirectory String.
Mulai skrip dengan direktori kerja ini.

condition String.
Evaluasi ekspresi kondisi ini untuk menentukan apakah akan menjalankan tugas ini.

continueOnErrorboolean.
Terus berjalan bahkan pada kegagalan?

displayName String.
Nama yang dapat dibaca manusia untuk tugas tersebut.

targettarget.
Lingkungan tempat menjalankan tugas ini.

enabledboolean.
Jalankan tugas ini ketika pekerjaan berjalan?

env kamus string.
Variabel untuk dipetakan ke lingkungan proses.

name String.
ID langkah. Nilai yang dapat diterima: [-_A-Za-z0-9]*.

timeoutInMinutes String.
Waktu untuk menunggu tugas ini selesai sebelum server mematikannya.

Catatan

Alur dapat dikonfigurasi dengan batas waktu tingkat pekerjaan. Jika interval batas waktu tingkat pekerjaan berlalu sebelum langkah Anda selesai, pekerjaan yang sedang berjalan (termasuk langkah Anda) dihentikan, bahkan jika langkah dikonfigurasi dengan interval yang lebih lama timeoutInMinutes . Untuk informasi selengkapnya, lihat Batas Waktu.

retryCountOnTaskFailure String.
Jumlah percobaan ulang jika tugas gagal.

Keterangan

Kata powershell kunci adalah pintasan untuk tugas PowerShell. Tugas menjalankan skrip menggunakan Windows PowerShell (di Windows) atau pwsh (Linux dan macOS).

Setiap sesi PowerShell hanya berlangsung selama durasi pekerjaan yang dijalankannya. Tugas yang bergantung pada apa yang telah di-bootstrap harus berada dalam pekerjaan yang sama dengan bootstrap.

Pelajari selengkapnya tentang kondisi dan batas waktu.

Preferensi tindakan kesalahan

Kecuali ditentukan lain, preferensi tindakan kesalahan default ke nilai stop, dan baris $ErrorActionPreference = 'stop' ditambahkan ke bagian atas skrip Anda.

Saat preferensi tindakan kesalahan diatur ke berhenti, kesalahan menyebabkan PowerShell mengakhiri tugas dan mengembalikan kode keluar bukan nol. Tugas ini juga ditandai sebagai Gagal.

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

Abaikan kode keluar terakhir

Kode keluar terakhir yang dikembalikan dari skrip Anda diperiksa secara default. Kode bukan nol menunjukkan kegagalan langkah, dalam hal ini sistem menambahkan skrip Anda dengan:

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

Jika Anda tidak menginginkan perilaku ini, tentukan ignoreLASTEXITCODE: true.

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

Pelajari selengkapnya tentang kondisi dan batas waktu.

Contoh

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

Lihat juga