تعريف 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 سلسله.
ما لم يتم تحديد خلاف ذلك، يتم تعيين تفضيل إجراء الخطأ افتراضيا إلى إيقاف القيمة. راجع القسم التالي لمزيد من المعلومات.

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 فقط طوال مدة المهمة التي يتم تشغيلها فيها. يجب أن تكون المهام التي تعتمد على ما تم تمهيده في نفس مهمة bootstrap.

تعرف على المزيد حول الشروطوالمهلات.

تفضيل إجراء الخطأ

ما لم يتم تحديد خلاف ذلك، يتم تعيين تفضيل إجراء الخطأ افتراضيا إلى القيمة 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

راجع أيضًا