GH-200 practice question 15 of 15

A development team has been using a Powershell script to compile and package their solution using existing tools on a Linux VM, which has been configured as a self-hosted runner. They would like to use the script as-is in an automated workflow. Which of the following should they do to invoke their script within a workflow step?

Full set: 100 questions
Answer options
A: Configure a self-hosted runner on Windows with the requested tools.
B: Use the YAML powershell: step.
C: Run the pwsh2bash command to convert the script so it can be run on Linux.
D: Use the YAML shell: pwsh in a run step. Correct answer
E: Use the actions/run-powershell action to invoke the script.
Correct Answer:
D. Use the YAML shell: pwsh in a run step.
Explanation

To execute a PowerShell script on a Linux runner, the run step in the workflow must specify the shell to be used. PowerShell Core is cross-platform, and its executable on Linux is pwsh. By setting shell: pwsh, the workflow instructs the runner to use the PowerShell Core engine to interpret and execute the script commands provided in the run block. This allows the existing script to be used "as-is" on the configured Linux runner.

Why Incorrect

A. This contradicts the scenario, which specifies an existing Linux VM. The goal is to use the current setup, not create a new Windows one.
B. The powershell: keyword is not a valid top-level key for a workflow step. The correct syntax involves using shell: within a run step.
C. Converting the script to Bash (pwsh2bash) violates the requirement to use the script "as-is" without modification.
E. The actions/run-powershell action is generally for Windows runners and is less direct than using the built-in shell keyword for cross-platform execution.

References

1. GitHub Docs. (2023). Workflow syntax for GitHub Actions. Retrieved from https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjobidstepsshell. The documentation specifies pwsh as a built-in shell option for cross-platform PowerShell.

2. GitHub Docs. (2023). Choosing the shell that your commands are run in. Retrieved from https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-the-shell-that-your-commands-are-run-in. This section provides examples of using shell: pwsh for running PowerShell commands.

Scroll to Top