Retrieve msiexec error code from script - scripting

I have 2 problems that I need help with:
I need to create a script to get the (error/success) code of an installation with msiexec.
Any resources, examples about this?
If my WIX Custom Action fails how can I return an error code for the installation?
Any examples?

check ERRORLEVEL environment variable
e.g. (C#) Environment.GetEnvironmentVariable("ERRORLEVEL")
return 3

Related

Post build task not working [Jenkins]

Can someone please help. I am trying to trigger a post-build action using the post-build action plugin. The log text that I inputted is returning false, hence not performing a post-build action. When I don't enter any text, it returns true.
This is a simple freestyle project that should print test if it matches the text
Post build setting
This is the console output returning false
Console output returning false
This is the output with no text
Output with no text
Any help will be appreciated. All I want to do is perform a post-build action depending on if my build fails or passes. Alternate solution is welcomed
Thanks
The root cause is your job has no any log out in Job Build Stage, please see Post build task plugin's help, this plugin will search job build log to find the text you specified in plugin.
A quick way to re-try is add a Build Step to print out something:
1. Execture shell (if job executed on Linux machine)
2. Execute windows batch (if job execute on Window machine)
A Job configure example:

How to get MSBuild to print command output in post-build task?

I have a Visual Studio 2005 solution/vcproj which has a post-build task that runs unit tests. I want to build it using msbuild.exe.
However, when the tests fail, I do not see any output logged to the console (I've verified that output is logged when executed at the command line.) I can see the output if I use the /v:detailed parameter. Is there a better way to do this? Ideally, I only want to see the output if a test fails.
Thanks.
To answer my own question, the best way I've found is to call msbuild and pass parameters down to vcbuild:
msbuild ... /p:VCBuildAdditionalOptions="/M /logfile:logfile.log" || type logfile.log
So if the build fails, the errors that were logged will be output at the end of the build which is sufficient for me.

CA conditions during REINSTALL

I have a custom action which must be executed if the spesial feature's action state is "install". Now I am using next condition:
(&ca_feature=3 AND NOT &ca_feature=2) OR (!ca_feature=3 AND PATCH) .
I want to execute it also in Modify Mode. When the feature is already installed and user do not want to delete it. I thaught to append OR (REINSTALL><ca_feature OR REINSTALL=ALL) to my condition string. but it seems not working.. I can't get how the MSI is working in some situations, that is my problem. but i also can't find the answer in the internet.
Please,tell me what i'am doing/understanding wrong?thanx in advance
The condition looks correctly. The last part with REINSTALL would be true if your feature is to be reinstalled.
Although you can try to use !ca_feature=3 instead of REINSTALL><ca_feature: that would run the CA when the feature is installed.
I think your condition could look this way:
(&ca_feature=3) OR (!ca_feature=3 AND NOT (REMOVE><ca_feature OR REMOVE=ALL))
It would run the CA when this feature is scheduled for install, or if it's installed and is not scheduled for remove.
This part AND NOT &ca_feature=2 in the first parenthesis is redundant because &ca_feature cannot be equal to 2 if it's already equals 3.
Use MSI verbose logging to better understand what's going on. Run your installation this way:
msiexec /i package.msi /l*vx log.txt
When a feature state changes or a property is modified, you'll see a message in the log. Then you'll be able to compare the actual values with your expectations. Use other operation switches instead of /i to run it in modify or remove mode.

Capture output of regsvr32 in an InvokeProcess TF Workflow Activity

I have a build process setup to build a managed solution using team build. This solution requires an unmanaged component be registered with the server before we build the solution as we interface with it via COM.
The activity (InvokeProcess) I use to register the ComObject looks something like this
regsvr32.exe /s ComObject.ocx
The activity (InvokeProcess) I use to unregister it looks something like this
regsvr32.exe /u /s ComObject.ocx
I have also added the WriteBuildMessage and WriteBuildError to both InvokeProcess activities using stdOutput and errOutput as the message for each action. I also make sure to set the build message importance to high.
It's my understanding that this should redirect the standard output and error output into these logging activities.
The registrion, build, and unregistrion works just fine as long as I do not set the /maxcpucount argument of MSBuild to anything greater than 1.
Once I set it to something greater than 1, our cleanup script at the end of the process fails with this error message when attempting to delete the file in question.
Access to the path '...\ComObject.ocx' is denied.'
I think what's happening is that the unregister activity is failing to unregister ComObject.ocx from the server because MSBuild isn't done with it when it's running across multiple cpu's. Then when I get down to try and delete it from the build server, it's still registered with the system and will fail with the access denied error.
So how do I get regsvr32 output to the stdOutput and errOutput so that the WriteBuildMessage and writeBuildError activities will properly display it in the build logs. If I call regsvr32 with a file that doesn't exist, I see nothing in the build log.
I hope this is makes sense.
Update
The solution to this problem came from a minor tweak of pantelif's solution. What I did was in the if block that throws an exception, I do a WriteBuildError using this as the message:
String.Format("ErrorMessage: {0}", New System.ComponentModel.Win32Exception( System.Runtime.InteropServices.Marshal.GetL‌​astWin32Error() ).ToString() )
This allows me to get the error from regsvr32.exe and write it to the build log.
As for your first question:
I believe it's possible to capture the output, by applying the technique presented by E.Hofman here.
More specifically, if you construct within your 'InvokeProcess' a sequence like presented (pic also from Ewald's post):
& then assign 'WriteBuildMessage' to stamp the 'ErrorMessage', you shall probably end up with getting the output you desire in the generated build log.

SubWCRev.exe in msbuild to find local modifications

i want to execute SubWCRev.exe in msbuild to check for local modifications .if local modifications found then i want to display message on command prompt.
please tell me how can i use this.
thanks
Using MSBuild Exec task you can't get the output, so you'll have to write an MSBuild custom task to do that (Or an inline task if you are using MSBuild v4).
In that task you'll execute SubWCRev.exe, parse the result and set it to an output property.