manojlds / gocd-powershell-runner

A Powershell Task runner for gocd (http://www.go.cd)
Apache License 2.0
10 stars 5 forks source link

Failed running powershell task #1

Closed reidca closed 10 years ago

reidca commented 10 years ago

Setup a powershell task using 64 bit

[go] Start to execute task: Plugin with ID: gocd-powershell-runner. Launching command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command - Failed while running Powershell task

The server is 64 bit however the GO agent runs as a 32 bit process.

I see that the runner is calling Powershell 64 bit however a 32 bit process that needs to call a 64 bit version of Powershell needs to call C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe

manojlds commented 10 years ago

Thanks, forgot to handle this. Will add a fix soon.

manojlds commented 10 years ago

I have handled x86 processes better with the latest 1.1. Do check it out.

I do have a question, something I didn't notice before - should it be really failing in your case due to the sysnative issue? The C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe path should still have worked, albeit with the 32 bit Powershell, right?

reidca commented 10 years ago

Yes perhaps it should. I was guessing that was the problem since there was no other errors logged.

Do you know where I can see more information? Does it log to the standard go agent logs?

Thanks

Did you get chance to change the box size? I will check out the update tomorrow.

Carl

On 10 Jul 2014 21:50, Manoj notifications@github.com wrote: I have handled x86 processes better with the latest 1.1. Do check it out.

I do have a question, something I didn't notice before - should it be really failing in your case due to the sysnative issue? The C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe path should still have worked, albeit with the 32 bit Powershell, right?


Reply to this email directly or view it on GitHub: https://github.com/manojlds/gocd-powershell-runner/issues/1#issuecomment-48662442

reidca commented 10 years ago

Do you have any information on this? I have tried again using v1.1 and get the following error:

[go] Start to execute task: Plugin with ID: gocd-powershell-runner. Launching command: C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command - Failed while running Powershell task

manojlds commented 10 years ago

@reidca - Can you tell me exactly what you have configured to run in the task?

manojlds commented 10 years ago

@reidca - I have also created a 1.2 release with additional logging, and added the text area for arguments. Do try that if you have the time.

reidca commented 10 years ago

Ok upgraded to 1.2 and ran the task again. Same problem with same error. No more details from what I can see.

[go] Start to execute task: Plugin with ID: gocd-powershell-runner. Launching command: C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command - Failed while running Powershell task

I wonder whether the problem is this.

The task I am trying to run is not a script - In this case it is using built-in powershell (.NET) commands to perform a function. There is no script as this is unnecessary. Does your runner assume that there is a script present? I am adding the commands to run to the box labelled "script .ps1 file" because there is no other way to do this.

I would expect there to be a choice. Do you want to run a script or a command block. If you choose "script" then you get a box for the script filename and additional arguments to pass to it. If you choose "command" then you get a box to enter the commands to send to Powershell.exe.

Maybe the example below helps. This works using the "MORE" task type. I was hopeing your task runner would mean this is a little easier.

This example - that works - sets an environment variable to ensure the clients always use the correct server name for the GO server.

%POWERSHELL% is defined as C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe

[go] Start to execute task:

[System.Environment]::SetEnvironmentVariable(\"GO_SERVER\",\"myservername.domain.co.uk\", \"Machine\"); $newVariable = [System.Environment]::GetEnvironmentVariable(\"GO_SERVER\"); Write-Host \"GO_SERVER environment variable: $newVariable\";

.

Thanks

Carl

manojlds commented 10 years ago

That explains it. Yeah, the plugin expects a script. And allowing ability to just run a command is something I wanted to add next, and will do so soon.

I am not sure why the error information is not coming out well. I will have to talk to the Go team about that.

reidca commented 10 years ago

Ok I thought that was already there - what is the choice between File and Command for now?

manojlds commented 10 years ago

The first one uses -File to run a script.

The second one used -Command - (note the trailing -) to place the script in stdin of Powershell

Something like: powershell -Command - < script.ps1

From docs:

-Command Executes the specified commands (and any parameters) as though they were typed at the Windows PowerShell command prompt, and then exits, unless NoExit is specified. The value of Command can be "-", a string. or a script block.

If the value of Command is "-", the command text is read from standard
input.
reidca commented 10 years ago

Not sure what the value of a Command that just calls a file would be? How is that better than just using File?

manojlds commented 10 years ago

Because of this - https://connect.microsoft.com/PowerShell/feedback/details/750653/powershell-exe-doesn-t-return-correct-exit-codes-when-using-the-file-option

It's a very serious bug that has not been resolved in ages.

Also, I am looking at feature parity with Powershell support in TeamCity.

On Wed, Aug 6, 2014 at 7:26 PM, reidca notifications@github.com wrote:

Not sure what the value of a Command that just calls a file would be? How is that better than just using File?

Reply to this email directly or view it on GitHub https://github.com/manojlds/gocd-powershell-runner/issues/1#issuecomment-51337457 .

manojlds commented 10 years ago

So I will close this issue, and raise one for adding arbitrary command execution feature.

reidca commented 10 years ago

Ok that's interesting.

I have just up-voted that Connect entry. There is another related exit code error here which has also not been fixed: https://connect.microsoft.com/PowerShell/feedback/details/750654/powershell-exe-returns-a-passing-0-exit-code-when-a-parsererror-is-thrown