Detect remote runcommand failed when running msdeploy - powershell

I am running msdeploy (in powershell, as part of a script) with a runcommand provider as a postsync step, which runs a batch file on the remote machine. The batch file just executes exit /b 1 which causes it to return a failure code.
I am using msdeploy v3, and have specified successReturnCodes=0 as a provider parameter.
I can see the batch file executing, I can see that msdeploy recognises that it's an error, and logs the fact:
Performing '-postSync'...
Info: Using ID '892ee111-27c1-458d-888d-ead28fcab742' for connections to the remote server.
Info: Using ID '49ee88fc-0e1d-4eff-8a75-bccf0e7d680a' for connections to the remote server.
Info: Updating runCommand (d:\testdeploy\test\test.bat).
Info:
Info: C:\Windows\system32>exit /b 1
Error: (13/06/2013 6:06:03 PM) An error occurred when the request was processed on the remote computer.
Error: The process 'C:\Windows\system32\cmd.exe' (command line '') exited with code '0x1'.
Error count: 1.
Error during '-postSync'.
Total changes: 1 (0 added, 0 deleted, 1 updated, 0 parameters changed, 6 bytes copied)
D:\TestDeploy> $LASTEXITCODE
0
However, msdeploy returns successfully, $LASTEXITCODE is 0.
Is there any way to tell that msdeploy has actually caught an error? (without resorting to capturing the output of msdeploy and checking for the presence of 'Error count:'? :)

It seems that if you remove successReturnsCodes, it will only report as a warnig but msdeploy will return the correct return code.
I'd recommend you file this as a bug on the MSDeploy forums.

It turns out it was due to a mix up in versions between msdeploy v2 and v3. The only combination that will return the exit code correctly is v3 client and v3 service. I was using the v3 client but mistakenly connecting with it to a v2 service.
Richard Szalay is correct, the successReturnCodes just changes the log of the return code from warning to info.

Related

Continue after a failing command in appveyor

In appveyor I use the statement:
- initexmf --admin --force --mklinks
but due to a problem it gives the message:
initexmf --admin --force --mklinks
Sorry, but "MiKTeX Configuration Utility" did not succeed for the following reason:
Script configuration file not found.
The log file hopefully contains the information to get MiKTeX going again:
C:\ProgramData\MiKTeX\2.9\miktex\log\initexmf_admin.log
The system cannot find the path specified.
Command exited with code 1
due to the error code the process terminates and I cannot type the C:\ProgramData\MiKTeX\2.9\miktex\log\initexmf_admin.log anymore, so a bit hard to debug ...
questions:
How to continue after an error
How to stop after the outputting the file (exit 1 ?)
To run a script on failure use on_failure section, for example to push initexmf_admin.log to artifacts:
on_failure:
- appveyor PushArtifact C:\ProgramData\MiKTeX\2.9\miktex\log\initexmf_admin.log

jasmine-node outputs silently when unhandled exceptions happen in tests

I'm having a problem where jasmine-node silently fails if unhandled exceptions happen in a test.
If I run a single file, everything is OK and I get the expected jasmine output:
./node_modules/jasmine-node/bin/jasmine-node spec/unit/accessControlSpec.js
Finished in 0.011 seconds
4 tests, 6 assertions, 0 failures, 0 skipped
But, if I run all specs in a folder, it fails silently.
./node_modules/jasmine-node/bin/jasmine-node spec/unit
Tried --verbose and --captureExceptions but no luck.
In this specific case, some code inside a test was calling a method that didn't exist.
So, turns out the problem is that I'm not calling the correct command because I didn't install jasmine-node globally.
The correct way is:
node ./node_modules/jasmine-node/lib/jasmine-node/cli.js ./spec/unit
This is further described here: Command Line Usage

error on Teamcity running command line custom script

I'm trying to run command line -custom script on Teamcity and getting this error (127):
[02:22:25][Step 1/1] /mnt/teamcity/temp/agentTmp/custom_script8657691082445726475: 1: /mnt/teamcity/temp/agentTmp/custom_script8657691082445726475: ./run.sh: not found
[02:22:25][Step 1/1] Process exited with code 127
[02:22:26][Step 1/1] Step run protractor test (Command Line) failed
any ideas?
It looks like some dependency of your script is not found where it expects it:
./run.sh: not found
Is that the actual script you are running? or is your script trying to call that script?
what solved it was adding 'Agent Requirements' (under build Configuration Settings) saying that 'system.agent.name' equals to the name of the Agent we use.

Powershell Try Catch

I've a simple powershell script below which basically executes the abc.exe (console application) with few arguments.
& abc.exe ar1 ar2
abc.exe file is .net so it has it's own exception handler.
Whenever abc.exe throws exception I would like the Powershellscript to catch and log/echo.
Could someone help me how to achieve above.
No.
The exception in abc.exe will bubble up to main method, not any more. But you can check the ERRORLEVEL of abc.exe by looking at $LASTEXITCODE. (Check this)
What you should do:
Your abc.exe, as any exe, should return errorlevel 0 if everything was ok and other number in case of error
Abc.exe main method could write an error message in case of problem. This way when you invoke it from a PowerShell script you will see the error message in console and later your script will check for errorlevel.
Additionally, you can also use different exitcodes for errorlevels in abc.exe to provide some information to PowerShell script. For example these are 7zip error levels.
0 --> No error
1 --> Warning
2 --> Fatal error
7 --> Command line error
8 --> Not enough memory for operation
255 --> User stopped the process

Chain psexec and nunit is not working (psexec exit with code 1 and nunit is crashed)

Sorry for unclear subject but i really don't understand where problem.
I use a system for autotests c#+webdriver for chrome + nunit (2.6) + cc.net ( 1.6.7981.1)
And my tests is run on remote machine (Windows XP SP 2 x86)via psexec which start bat file on remote machine
bat file includes 2 commands:
run msbuild
run nunit-console
Well, psexec has next arguments
/accepteula \MachineName -u Login -p Pass -s Path\start.bat
Bat file has next command
nunit-console-x86.exe "%PROJECT_FOLDER%\Path\Tests.dll" "/xml=%TEST_RESULT_PATH%"
When cc.net launch psexec tests is started and the tests work during some time. Unexpected, psexec exit with code 1
message level="Error">Path\start.bat exited on MachineName with error code 1. message
But nunit-console on remote machine is continue working
And after some time console is crashed with error
szAppName : nunit-console-x86.exe szAppVer : 2.6.0.12051
szModName : kernel32.dll szModVer : 5.1.2600.2180 offset :
0001eb33
Message from Event log
Application: nunit-console-x86.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException Stack: at
System.IO._Error.WinIOError(Int32, System.String) at
System.IO._ConsoleStream.Write(Byte[], Int32, Int32) at
System.IO.StreamWriter.Flush(Boolean, Boolean) at
System.IO.StreamWriter.Write(Char[], Int32, Int32) at
System.IO.TextWriter.WriteLine(System.String) at
System.IO.TextWriter.WriteLine(System.String, System.Object) at
System.IO.TextWriter+SyncTextWriter.WriteLine(System.String,
System.Object) at System.Console.WriteLine(System.String,
System.Object) at NUnit.ConsoleRunner.Runner.Main(System.String[])
at NUnit.ConsoleRunner.Class1.Main(System.String[])
If run nunit locally than no problem(nunit-console works fun).
Some time ago system worked, and i don't know what is changed (This is most bad case)
How can i resolve this problem?
Thanks!
This problem is resolved!
Now system is working