n mi Upgrade database to specified version in automated build task  
Author Message
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

We are using team build to run a nightly build and deployment to our test environment.

We are thinking about to create a DBScripter.exe app to upgrade our Oracle DB to the specified version. It will look for change scripts and handle the upgrade of the database to a specified version.

What can be a good approach to integrate this in the build process I was thinking about calling this at the BeforeCompile Event and the Exec command. But if the return code is less than zero from DBScripter.exe I want to cancel the build. How can I check for the return code and cancel the build if there is any error

I would also thinking about using the assembly info task to apply a custom build number to the assembly files. How can I access the build number and send it as a paramter to the DBScripter.exe app

Is this AfterComile task the best place to put the code to do XCOPY deployment



Visual Studio Team System19  
 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Yes I think it can be a good idea, the point of execution, it depends on you, but the point you say seems ok, about the error return, when you make a custom task, and implement the ITask interface, or base class Task, you have to implement Execute method, which returns a boolean, so you can return false if it fails.

About accesing the build numbre for using it in your task, first of all you have to make a property in your task, and apply [Required] attribute if you want to set it as mandatory:

[Required]

public string BuildNumber

{

get { return _buildNumber; }

set { _buildNumber = value; }

}

Then, when you implement your custom task in the .proj file, there are some fields you can use, one of them is the build number, and it will work like this:

<UsingTask TaskName="RS.BuildTask.PackBinTask" AssemblyFile="RS.BuildTask.dll" />

<Target Name="AfterDropBuild">

<PackBinTask BuildNumber="$(BuildNumber)" />

</Target>

To give value to your property, you just put its name into the Xml line (BuildNumber) and you can reach build number value of the build with $(BuildNumber) which is one of the values avaliable during the build and managed by Team Build



 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Thank you for the response.

I have now added a class library name Buildtask to my solution. It contain a class called DBScripter:

public class DBScripter : Task

{

public override bool Execute()

{

StreamWriter writer = new StreamWriter( );

writer.WriteLine("execute task");

writer.Close();

return false;

}

}

I have a PROJ file I have generated from the wizard. At the end of the file have I added the following lines:

  <UsingTask TaskName="Buildtasks.DBScripter" AssemblyFile="BuildTasks.dll" />
  <Target Name="UpdateDB">
    <DBScripter/>
  </Target>

</Project>

But this task do not run if I build from Team System or just MSBild TFSBuild2.proj.  If I run MSBUILD TFSBuild2.proj /target:UpdateDB only the task is run.

How can I get the task to run with the team build

 Edit:

If I run this stripped proj file the task will not run. But if I remove the import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets linje it work..  I need that for the rest of my build tasks.

< xml version="1.0" encoding="utf-8" >

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets" />

<UsingTask TaskName="Buildtasks.DBScripter" AssemblyFile="BuildTasks.dll" />

<Target Name="UpdateDB">

<DBScripter/>

</Target>

</Project>

 


 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

The taeget name you specify "UpdateDB" is not correct, here you have to specify in which step of the build do you want to execute the task, here I post you a reference on the build steps (take care, it was from RC or beta3 and maybe there are changes)

1.BeforeEndToEndIteration*
2.BuildNumberOverrideTarget*
3.InitializeEndToEndIteration
4.BeforeClean*
5.CoreClean
6.AfterClean*
7.Clean
8.InitializeBuild
9.BeforeGet*
10.InitializeWorkspace
11.CoreGet
12.AfterGet*
13.PreBuild
14.BeforeCompile*
15.CoreCompile
16.AfterCompile*
17.Compile
18.GetChangeSetsAndUpdateWorkItems
19.PostBuild
20.BeforeTest*
21.CoreTest
22.AfterTest*
23.Test
24.PackageBinaries*
25.TeamBuild
26.BeforeDropBuild*
27.CoreDropBuild
28.CopyLogFiles
29.AfterDropBuild*
30.DropBuild
31.AfterEndToEndIteration*
32. EndToEndIteration

Those with an "*" is the ones you can use in your target, ONLY THAT ONES, the other ones are reserved for team build

You can also xtend the targets, but you have to modify another file of Team Build, you can find info in the Team Build reference in Visual Stdio 2005 SDK



 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

I'm now running the following code:

<UsingTask TaskName="Buildtasks.DBScripter" AssemblyFile="BuildTasks.dll" />

 

<Target Name="BeforeCompile" DependsOnTargets="$(UpdateDB)">

</Target>

 

<Target Name="UpdateDB">

<DBScripter/>

</Target>

This seems to work OK. But if I delete my output testfile generated from the UpdateDB task, it will not rerun if I rebuild.  Even if I delete the release directory the same happens(nothing..). If I do a invalid proj file and get a failed build, and change it back again to a valid proj file, the testfile written from UpdateDB is generated again.

It looks like the build is shipping the target the second time. But the output files should is not up-to-date with respect to the input files if I have deleted them Can I force a rerun of the task on every build


 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

The target must execute every build (well assuming you reach the step), so maybe it's some error in the task can you check it

I have done several tasks, and they were run every build without problems.



 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Ok, but I will check it. So far I have just hardcoded return false in the Execute metod. Still still the build is succeeded, can I configure the build to fail if execute return false
 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Hmm as far as I remember (I don't have Tfs right here now) return false only affects to the log of the build, you can do another thing which is add "failed" steps to the build, here http://blogs.msdn.com/nagarajp/archive/2006/02/03/524418.aspx you have a sample on that, and I think it was also possible to make the build fail, but check it

 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Thank you. I have tried this, but it looks like the build is continuing anyway..

But maybe another approach can be a make a deploy.cmd file that call the DBScripter and deploy the application. I guess I can use buildnumber and other information as parameters. The cmd file can check for the return code of DBScripter app and if OK start to xcopy the files.

How can I check that the build is sucessfull so I only call the deploy.cmd file if sucessfull Or can I check on the returncode of the Exec command to DBScripter in MSBuild and if OK use the copy command from MSBuild


 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

You can use the eenting service to check when a build finishes and check if it was successful, take a look at the documentation in the Visual Studio 2005 SDK

 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

"Eenting" Is there a typing error here..
 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Ufff sorry, yes is typing error, I meant eventing service

 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Do you have any information about this "build complete" event In the SDK I can see the "eventing service" and how to subscribe to events, but not an overview over the available events.
 
 
Milzit





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

Thank you for the help

The Build will fail if the task return false as I wanted, I was wrong in the previous post..


 
 
Luis Fraile





PostPosted: Team Foundation Server - Build Automation, n mi Upgrade database to specified version in automated build task Top

There is not so much information about the data the events send, you can take a look to its structure (of the data) to the Xsd which defines it, it's on the server, in the folder:

%Program Files%\Microsoft Visual Studio 2005 Team Foundation Server\Web Services\Services\v1.0\Transforms

And for build completion is "BuildCompletionEvent.xsd", also I would recommend you to subscribe to the event and see what do you recieve.