question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

powershell task should now prefer `pwsh` on mac/linux

See original GitHub issue

The executable has changed now for powershell core to pwsh instead of powershell, even on Windows. On Mac/Linux we should definitely prefer pwsh and fallback to powershell for back-compat. On Windows, I think we should just try powershell since I’m not sure why that wouldn’t be in the PATH and preferring pwsh seems incorrect.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ericsciplecommented, Jan 9, 2018

fixed in master https://github.com/Microsoft/vsts-tasks/pull/6175

will roll out with the next deployment. the next deployment starts next week and will roll out over a week or two.

0reactions
dhabierrecommented, Dec 16, 2019

I’ve found my problem.

I am using Terraform to create and setup a Linux agent with the remote-exec provisionner:

provisioner "remote-exec" {
  inline = [
    # Powershell
    # --------------------------------------------------------------------------------
    "sudo snap install powershell --classic",
    "sudo pwsh -NoLogo -NoProfile -NonInteractive -Command Install-Module PowerShellGet -Repository PSGallery -Force",
    "sudo pwsh -NoLogo -NoProfile -NonInteractive -Command Install-Module Az -AllowClobber -Force",
    # Azure DevOps Agent
    # --------------------------------------------------------------------------------
    "mkdir agent && cd agent",
    "wget https://vstsagentpackage.azureedge.net/agent/2.163.1/vsts-agent-linux-x64-2.163.1.tar.gz",
    "tar zxvf ./vsts-agent-linux-x64-2.163.1.tar.gz",
    "./config.sh --unattended --url ${var.serverUrl} --auth pat --token ${var.pat} --pool ${var.agentPool} --agent ${azurerm_virtual_machine.virtualmachine[count.index].name}",
    "sudo ./svc.sh install && sudo ./svc.sh start"
  ]

When executing the ./config.sh command, the file .path is created with the current $PATH and it is used to setup the PATH capability. But but the path does not contains /snap/bin folder!

And thus the Azure Powershell Task failed with which pwsh => not found.

=> set the PATH before executing ./config.sh:

provisioner "remote-exec" {
  inline = [
    # Powershell
    # --------------------------------------------------------------------------------
    <...>
    # Azure DevOps Agent
    # --------------------------------------------------------------------------------
    "mkdir agent && cd agent",
    "wget https://vstsagentpackage.azureedge.net/agent/2.163.1/vsts-agent-linux-x64-2.163.1.tar.gz",
    "tar zxvf ./vsts-agent-linux-x64-2.163.1.tar.gz",
    # *******************************************************************************************
    "export PATH=\"$PATH:/snap/bin\"",
    # *******************************************************************************************
    "./config.sh --unattended --url ${var.serverUrl} --auth pat --token ${var.pat} --pool ${var.agentPool} --agent ${azurerm_virtual_machine.virtualmachine[count.index].name}",
    "sudo ./svc.sh install && sudo ./svc.sh start"
  ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started with PowerShell Core on Windows, Mac, and ...
Today we have a guest post from Honorary Script Guy and Microsoft Premier ... This version of PowerShell will be different than the...
Read more >
Determine the OS version, Linux and Windows from Powershell
The OS-specific ones I see for now are $IsLinux , IsMacOS and $IsWindows . This is of at least PowerShell version 6.0.0-rc and...
Read more >
I'm interested now that PowerShell is cross platform. For ...
that I want to use both on Windows and Linux. Since there are certain tasks that are more suitable with regular shell, I...
Read more >
Advanced PowerShell Automation - CBT Nuggets
This advanced Microsoft Advanced PowerShell Automation prepares systems administrators to automate complex administrative tasks using Windows PowerShell.
Read more >
Adopting PowerShell (on Mac) | Philippe.me
This one doesn't have a direct equivalent. Like on Windows you would generally escalate your session: sudo pwsh -NoProfile will spawn an admin- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found