Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation/Setup - Use of Write-Host in Install-ChocolateyPath.ps1 prevents non-interactive installation of Chocolatey itself #1560

Closed
meastp opened this issue May 4, 2018 · 9 comments
Assignees
Milestone

Comments

@meastp
Copy link

meastp commented May 4, 2018

What You Are Seeing?

Trying to install Chocolatey in a Azure VM using "Power Shell on Target Machines" from VSTS fails because Write-Host (which is not supported in non-interactive mode) is used in Install-ChocolateyPath.ps1:84

I fell back to downloading and modifying the .nuget-package manually, and modifying the mentioned line from:

    Write-Host "PATH environment variable does not have $pathToInstall in it. Adding..."

to:

    try {
      Write-Host "PATH environment variable does not have $pathToInstall in it. Adding..."
    } catch {
      Write-Output "PATH environment variable does not have $pathToInstall in it. Adding..."
    }

error output exerpt from VSTS before the above fix was done:

2018-05-04T10:26:01.8573607Z System.AggregateException: Failed to execute the powershell script. Consult the logs below for details of the error.
2018-05-04T10:26:01.8583423Z A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows. ---> System.Management.Automation.CmdletInvocationException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows. ---> System.Management.Automation.Host.HostException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
2018-05-04T10:26:01.8584676Z    at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.ThrowNotInteractive()
2018-05-04T10:26:01.8584988Z    at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.get_ForegroundColor()
2018-05-04T10:26:01.8585281Z    at Microsoft.PowerShell.Commands.ConsoleColorCmdlet.get_ForegroundColor()
2018-05-04T10:26:01.8585538Z    at Microsoft.PowerShell.Commands.WriteHostCommand.ProcessRecord()
2018-05-04T10:26:01.8585802Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2018-05-04T10:26:01.8586033Z    --- End of inner exception stack trace ---
2018-05-04T10:26:01.8586334Z    at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
2018-05-04T10:26:01.8586657Z    at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
2018-05-04T10:26:01.8586992Z    at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
2018-05-04T10:26:01.8587365Z    at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2018-05-04T10:26:01.8587744Z    at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2018-05-04T10:26:01.8588097Z    at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
2018-05-04T10:26:01.8588417Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.PowershellExecutor.<>c__DisplayClass28_0.<Invoke>b__0()
2018-05-04T10:26:01.8590069Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.<>c__DisplayClass19_0`1.<Execute>b__0()
2018-05-04T10:26:01.8590547Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.Execute(Action action)
2018-05-04T10:26:01.8590864Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.Execute[T](Func`1 action)
2018-05-04T10:26:01.8591284Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.PowershellExecutor.Invoke(String errorContextMessage, Boolean writeResultToLog, Boolean isCancellable, ActionPreference errorActionPreference)
2018-05-04T10:26:01.8591635Z    --- End of inner exception stack trace ---
2018-05-04T10:26:01.8592089Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.PowershellExecutor.Invoke(String errorContextMessage, Boolean writeResultToLog, Boolean isCancellable, ActionPreference errorActionPreference)
2018-05-04T10:26:01.8592882Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.ScriptExecutor.ExecuteScript(IPowerShell powerShell, String script, String arguments, Boolean isScriptDotSourced, Boolean useHttp)
2018-05-04T10:26:01.8593459Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.DeploymentService.RunPowerShellScripts(DeploymentMachineSpecification deploymentMachine, ScriptSpecification scriptSpecification, ScriptSpecification initializationScriptSpecification, String applicationPath, IPowerShell powerShellSession)
2018-05-04T10:26:01.8594528Z ---> (Inner Exception #0) System.Management.Automation.CmdletInvocationException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows. ---> System.Management.Automation.Host.HostException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.
2018-05-04T10:26:01.8595395Z    at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.ThrowNotInteractive()
2018-05-04T10:26:01.8595716Z    at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.get_ForegroundColor()
2018-05-04T10:26:01.8596009Z    at Microsoft.PowerShell.Commands.ConsoleColorCmdlet.get_ForegroundColor()
2018-05-04T10:26:01.8596281Z    at Microsoft.PowerShell.Commands.WriteHostCommand.ProcessRecord()
2018-05-04T10:26:01.8596573Z    at System.Management.Automation.CommandProcessor.ProcessRecord()
2018-05-04T10:26:01.8597222Z    --- End of inner exception stack trace ---
2018-05-04T10:26:01.8597481Z    at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
2018-05-04T10:26:01.8597811Z    at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
2018-05-04T10:26:01.8598135Z    at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
2018-05-04T10:26:01.8598509Z    at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2018-05-04T10:26:01.8598888Z    at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2018-05-04T10:26:01.8599238Z    at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
2018-05-04T10:26:01.8600065Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.PowershellExecutor.<>c__DisplayClass28_0.<Invoke>b__0()
2018-05-04T10:26:01.8600501Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.<>c__DisplayClass19_0`1.<Execute>b__0()
2018-05-04T10:26:01.8600827Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.Execute(Action action)
2018-05-04T10:26:01.8601156Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Utilities.RetryExecutor.Execute[T](Func`1 action)
2018-05-04T10:26:01.8601558Z    at Microsoft.VisualStudio.Services.DevTestLabs.RemoteDeployer.Deployment.PowershellExecutor.Invoke(String errorContextMessage, Boolean writeResultToLog, Boolean isCancellable, ActionPreference errorActionPreference)<---

What is Expected?

Installation should work with the default installation method, without having to download the nuget-package manually.

@ferventcoder
Copy link
Member

Write-Output is a bit dangerous as it means that is returned at the end of the method, and we just want notification. This should only affect installation of Chocolatey as after that you would be using Chocolatey's built in PowerShell host.

What version of PowerShell is being used here?

@ferventcoder ferventcoder added this to the 0.10.11 milestone May 4, 2018
@ferventcoder
Copy link
Member

In this case the write-output might be fine but I'd like to use Write-Information if available (PowerShell 5+)

@meastp
Copy link
Author

meastp commented May 4, 2018

More information on the VSTS Task here: https://docs.microsoft.com/en-us/vsts/build-release/tasks/deploy/powershell-on-target-machines?view=vsts

(My VM is a recent windows server version, so I'd be okay with a PowerShell 5+ requirement)

FYI: No output except Write-Verbose is visible from scripts in VSTS, so it is not important (for me) whether you use Write-Output, Write-Information or something else. I believe anything except Write-Host is fine :)

EDIT: I can confirm that installing other software (using the -y parameter) works without modifications

@ferventcoder
Copy link
Member

@meastp yep, just during that install when it is using system PowerShell is where we'd hit these things. I know we've made adjustments for DSC, I thought we were covered on all of them but perhaps this was introduced more recently.

@meastp
Copy link
Author

meastp commented May 4, 2018

Thank you for the quick fix! Please add a reference to the commit where this is fixed / pull request, because this would make it easier to check when the fix is included in a release. :)

@ferventcoder
Copy link
Member

ferventcoder commented May 4, 2018

@meastp you must be new to choco git/source and how we do things. It will be here once it is pushed up. It will also be referenced in the CHANGELOG.

@ferventcoder
Copy link
Member

Also note the milestone above, that tells you what release it will go into.

@ferventcoder ferventcoder changed the title Use of Write-Host in Install-ChocolateyPath.ps1 prevents non-interactive installation of Chocolatey itself Installation/Setup - Use of Write-Host in Install-ChocolateyPath.ps1 prevents non-interactive installation of Chocolatey itself May 4, 2018
ferventcoder referenced this issue May 4, 2018
When PowerShell functions are used as part of installing Chocolatey
itself, it can cause issues if they call Write-Host. Note all of the
functions that are called from Setup, then wrap any existing with
try/catch.
@ferventcoder
Copy link
Member

You might also want to join the release announcements list at https://groups.google.com/forum/#!forum/chocolatey-announce to learn when new Chocolatey-related things are released.

@meastp
Copy link
Author

meastp commented May 6, 2018

Ah, ok, thanks for the explanation :) (I noticed the milestone and the fact that I did not find a commit with the fix confused me, that's all :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants