How to stop TFS Build when custom task fails - msbuild

I am calling a custom task (derived from Microsoft.Build.Utilities.Task) from the AfterDropBuild target in my TFSBuild.proj. If my Execute override returns false, the build log shows the task as FAILED, but I still get a successful build, which means that I do not realise there is a problem with the build. How do I ensure that the build as a whole also fails?
Edit: This is TFS 2008.

You've created a mismatch between logged errors and your task result. You need to first log an error, with Log.LogError. Then return !Log.HasLoggedErrors from your tasks, always. (from trick #2 in the book "MSBuild Trickery").

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:

Control Build Result in TFS2015

I'm using TFS2015 build definitions. Basically, I have a definition with a Visual Studio Build task and then a Visual Studio Test task. In this set up, if the Build task succeeds, but the Test task fails, the entire build fails. Is there a way to get this to set the result to "partiallySucceeded?"
The reason I want to do this is for our CodedUI tests. I want to be able to test a "partiallySucceeded" build using Release Management, but currently all of our builds are either "succeeded" or "failed," even though some of the "failed" ones are only due to 1 or 2 unit tests.
Make sure you set the "continue in error" checkbox on the test task.

TFS Build XAML Template at “AssociateChanges” step get all the Work Items since begging of the source code branch created

I have asked a similar question
TFS Build Configuration: get all the Work Items Details for a particular build
And based on the answer of above question I have the below query. I decided to start a new thread for new question rather than confusing people in same thread.
I am using a default XAML template for workflow of TFS build configuration. Now my requirement is that I need all the Work Items since beginning whenever I trigger a build event for any build definition regardless of last successful build.
Let say I have triggered first TFS build and it is succeeded then I triggered 2nd build and that is also succeeded.
Then I have opened the log file of 2nd successful build and goes to Diagnostics Tab of last build. Inside Diagnostics tab there is a section as “Associate the changesets that occurred since the last good build”
Inside this it will display a message like
"No change sets are submitted to build 'ABC…..'"
Whereas I require list of all the work items since beginning.
Please suggest me the changes which need to be done in XAML template so that I can get all the work items since the beginning of source code.
As we know, associate the changesets and work items only occurs since the last good build.
There is a simple workaround to achieve what you want, you can specify a previous changeset to queue a build, then build the latest changeset again, then you'll get the associated changesets and work items again. Refer to this blog: http://chamindac.blogspot.sg/2013/09/tfs-2012-get-release-build-with.html
Otherwise, you need to create a MSBuild custom task that makes a call to TFS for the items. Check the links below:
https://volatilecoding.com/2013/06/11/tfs-build-how-to-customize-work-item-association/
(this solution is for TFS2010/TF2012 build process template, you'll
need to work on TFS 2013 build process template).
http://devgorilla.net/?p=104

Is there a way to make NAnt catch exceptions and run a roll back script?

I am using NAnt to run some scrips for a deployment. It has simplified the process a lot. The issue now is that when there is an error I want the NAnt task to run my roll back scripts. However I only know of the option to fail on error for my tasks. Is there any sort of baked in way to set properties on error or to use the the chose statement to redirect the flow of the tasks if a previous task fails?
I found the answer looking for another question about NAnt (error handling in nant build scripts). This will fill the need I have to automatically kick off roll back scripts. Only thing catch is that is not a part of base NAnt but NAntContrib, but that a minor detail.

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.