Azure Devops steps.script vs CmdLine@2/ Bash@3

7.7k Views Asked by At

steps.script purpose is NOT clear. It allows only Inline Scripts to be executed? I actually want to use file with steps.script instead of inline script.

Cannot i use CmdLine@2 on windows or Bash@3 on linux/Unix Instead of steps.script.

Link for steps.script: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-script?view=azure-pipelines

Link for CmdLine@2: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/command-line?view=azure-devops&tabs=yaml

Link for Bash@3: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops

1

There are 1 best solutions below

0
On

The Script step is a platform agnostic step in YAML:

The script step runs a script using cmd.exe on Windows and Bash on other platforms.

You can also explicitly use pwsh: or powershell: or bash: to explicitly pick a certain script type. These are convenience shortcuts for the respective tasks, this is from the PowerShell@2 docs:

The PowerShell task also has two shortcuts in YAML:

- powershell:  # inline script
  workingDirectory:  #
  displayName:  #
  failOnStderr:  #
  errorActionPreference:  #
  warningPreference:  #
  informationPreference:  #
  verbosePreference:  #
  debugPreference:  #
  ignoreLASTEXITCODE:  #
  env:  # mapping of environment variables to add
- pwsh:  # inline script
  workingDirectory:  #
  displayName:  #
  failOnStderr:  #
  errorActionPreference:  #
  warningPreference:  #
  informationPreference:  #
  verbosePreference:  #
  debugPreference:  #
  ignoreLASTEXITCODE:  #
  env:  # mapping of environment variables to add

Both of these shortcuts resolve to the PowerShell@2 task. powershell runs Windows PowerShell and will only work on a Windows agent. pwsh runs PowerShell Core, which must be installed on the agent or container.

The same applies to the other YAML convenience shortcuts.

It's basically up to your preference which one you pick and whether you use the shortcut or the full step name.