Yami learns Powershell part deux
-
Okay, so i've got a powershell script. It does a thing. Yay!
When I run it with Bamboo, it hangs at the end. It doesn't seem to be returning control properly to the invoking process.
WTF?
Bamboo describes the invocation as
running command line: \nC:\Windows\System32\WindowsPowershell\v1.0\powershell.exe .\releaseFromBamboo.ps1 [arguments to script redacted]
-
What's with that
\n
in\nC:\Windows
? Is that normal?
-
looks like this is possibly a stdin redirection problem?
according to stackoverflow "PowerShell runs the commands in the script indicated through the -File switch and then waits for additional PowerShell commands from the standard input "
so redirecting stdin from nul might help?
Nota Bene: i don't poweshell, but i do google. YMMV HTH HAND ETC
-
What's with that \n in \nC:\Windows? Is that normal?
Yes, I copied from the unformatted log output instead of the pretty formatted output it shows in the proper console. It has linebreak characters in it, typically.
-
"PowerShell runs the commands in the script indicated through the -File switch and then waits for additional PowerShell commands from the standard input "
How do I make it not wait for further commands? That's probably what's doing it.
-
redirect stdin to nul?
powershell.exe script.ps1 arg1 arg3 arg3 <nul
?
-
I seem to have lost my logging doing that. It's just sitting there after running the command. Did that accidentally redirect standard out?
-
picture me shrugging. i just posted what google suggested to me.... but assuming redirection in powershell is like bash, that would have redirected stdin.
-
I think it's literally just putting together a command on the Windows command line, which begins with
powershell.exe
. so what's the Windows way to do that?
-
no idea.
i'll poke around in google a bit and see what pops out at me.
i assume the script does not hang when you run it in an interactive CMD console?
-
I think it's literally just putting together a command on the Windows command line, which begins with powershell.exe
Do you need to get back to the cmd shell after the powershell script then? In that case, finishing your script with
exit
should work?
-
return code of [C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -Noninteractive -Command ".\releaseFromBamboo.ps1 arg1 arg2 arg3" was -1 while expected 0
This hung until I stopped it, which is why it returned a -1, but that's the command I just tried and no dice.
-
I have a build script which is written in Powershell. As I don't want Notepad to open when I double click it, I created a helper batch file which just launches PS. I've done so with the following command:
powershell -executionpolicy bypass -File ProjectBuilder.ps1
So not really different from what you're having...
-
exit
at the end did nothing.Trying
-File
switch now...
-
When I run it from the command line, it's dumping back to the command line after. So. Fuck. I have no idea what's wrong now.
-
I don't powershell either, but shots in the dark are fun (okay, that sounded racist).
Try using
-NonInteractive
and/or-Command
.
-
Do you have Bamboo in "PowerShell" mode or "Script" mode? Bamboo treats PowerShell differently from normal scripts for some reason; maybe you've just encountered that reason.
-
I'm using an "executable" to run a "command". The executable path is C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe
That might be the wrong way to do it? Should I be using a "script" instead? I had a lot of trouble with that and ultimately ended up writing a script that calls the powershell script file, so it seemed like I was doing it wrong that way.
-
Look, Bamboo is a piece of shit. So let's get that out there right now.
That said, I know it has two types of script commands, one called "Script" and the other called "PowerShell". I think both assume you enter the contents of the script in the Bamboo web interface, but they might also have an option to pass in a file path.
Either way, I think it's worth trying the "PowerShell" action in Bamboo. Since you're running PowerShell.
-
I know it has two types of script commands, one called "Script" and the other called "PowerShell".
I think you might have the PowerShell plugin, which we don't have.
That said, the "script" command has a little "interpret as powershell" checkbox, which I do have.
-
Oh. I'm not the one who installed it/maintains it/even likes it, so I had no idea that wasn't a standard feature.
It probably does the same thing as that checkbox but without the checkbox.
-
Oh for fuck's sake.
Okay, so if I use a script tag, and I paste the EXACT SAME COMMAND into it, and I click "interpret as powershell", it works. It works by passing the same command I'm running to powershell.exe. But if I make an executable out of powershell.exe, and I pass that command to it, it hangs.
The problem is, this is a deploy job, and I can't find where in the deploy job interface I can say "only build on agents that have powershell". I can lock the deploy to a single agent, but it will only be available for the deploy jobs locked to it, and not to pick up capacity when I'm running a lot of builds.
I'm going to open a ticket, see if that helps.
-
The problem is, this is a deploy job, and I can't find where in the deploy job interface I can say "only build on agents that have powershell".
Ouch. You have some that don't?
-
Yeah, linux agents.
-
Ok well whatever. I can't even figure out Bamboo in our relatively simple environment. I can't even imagine what a nightmare it is using it on more than one OS.
Look on the bright side, you can buy Atlassian stock now! Invest directly into Bamboo!!!!!
-
If we could get rid of the few windows servers in our environment, I'd already be done with this project. At least the Windows 2009 boxes have powershell; the Windows 2003 ones that are being replaced don't.
-
You'd be better off getting rid of Bamboo, in my opinion.
-
-
And write all this crap by hand in Jenkins? No thanks.
If we were all windows, I'd suggest TFS, but we're mostly linux.
-
there was a windows 2009?
is it better than Windows 2008?
2008 R2. I just can't brain today, it's been a rough day.
-
2008 R2. I just can't brain today, it's been a rough day.
A recent, only slightly doctored, photo of @accalia:
-
A recent, only slightly doctored, photo of @yamikuronue:
-
that looks familliar.... ;-D
-
At least the Windows 2009 boxes have powershell; the Windows 2003 ones that are being replaced don't.
Then get it installed? Sure, it's PS 2.0 so it's a bit old but still... it's better than not having PS at all!
-
Eh. They're literally gone in a month or so.
-
In that case, don't bother
-
Necrodance!
How do I get Powershell to give me more details on an error?
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
pretty much tells me nothing
-
Oh, scrolling up, the answer to my previous issue with running on only Windows agents was to add a "Command Executable" called Powershell, located at "C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe". Then I can run my scripts using a "Command" task, pasting in a full command-line like
-inputformat none -Noninteractive -File .\releaseFromBamboo.ps1
in the "Argument" line. That can only run on agents that have the Powershell executable set up.
-
@Yamikuronue a web request is a language feature, you can catch the web exception, and exception to dig into it. But usually web requests look like this:
Var request = (HttpWebRequest) WebReqiest.Create(url)
Note there is no new in that statement
Your specific error says that something is calling downloadfile with two arguments, but download file does not take two arguments, so it doesn't know what to do
-
@Matches said in Yami learns Powershell part deux:
Your specific error says that something is calling downloadfile with two arguments, but download file does not take two arguments, so it doesn't know what to do
Wrong. I caught the inner exception and figured it out
try { $client.DownloadFile( $releaseURL, "${destination}\temp.tar.gz" ) } catch [System.Net.WebException] { if ($_.Exception.InnerException) { Write-Host $_.Exception.InnerException.Message } else { Write-Host $_.Exception.Message }
I had previously had the wrong quotes around the latter argument, and the innerException told me it couldn't resolve the path. It took me an hour or so to figure that out tho.
-
@Yamikuronue I'm still claiming credit for linking you to try catch and the specific web exception, and you can't stop me.
-
@Matches :) Fair enough. I knew that explanation was wrong as soon as I read it; the only thing I changed was the
${destination}
where it used to be hardcoded, so it always took two arguments.
-
@Yamikuronue i thought your download file method was a wrapper around a regular web request. Didn't realize it was an actual built in method, i work with api all day and have never had reason to use that method lol
-
@Matches Haha I'm nowhere near that sophisticated :D
-
-
@Matches said in Yami learns Powershell part deux:
i thought your download file method was a wrapper around a regular web request. Didn't realize it was an actual built in method, i work with api all day and have never had reason to use that method lol
It's one of those, what I like to call, "JUST FUCKING DO IT!" methods they've included in the .net framework.
Another one is,
File.SaveAllText()
. OrImage.GetThumbnailImage()
. Just really common shit a million applications have to do, so the framework has a function to JUST FUCKING DO IT in one line.
-
@blakeyrat said in Yami learns Powershell part deux:
so the framework has a function to JUST FUCKING DO IT in one line.
I like it when frameworks do framework-y things.
-
@Yamikuronue said in Yami learns Powershell part deux:
pretty much tells me nothing
See if htis helps at all: https://blogs.msdn.microsoft.com/mwories/2009/06/08/powershell-tips-tricks-getting-more-detailed-error-information-from-powershell/
-
@FrostCat oooh, nifty