Call custom tool from TFS build - deployment

We are using TFS2010 for our web sites's builds and we're in the process of creating fully automated builds. At the moment the sites are built and deployed in remote servers.
The sites contains several configuration files that we would like to transform as part of the build. As there are some rules to create the correct config files we would like to use a custom tool for that purpose (.exe), not to use xml transformations for it.
From what we can see in the build template, MSBuild copies the files to a drop folder and then pushes them to the remote IIS site. We would like to hook our custom tool to this process and do the transformations in the build server before the site is published. The problem is that the MSBuild task is a single node in the build template and we can't find a place where to invoke our tool. Before the MSBuild step, there is no code deployed to the drop folder, after the MSBuild step the code was already deployed to the remote server.
Any ideas on how to plug the custom tool in the correct workflow step?

What is the msbuild target, that you use? I think you can define your own target in csproj file to do the following:
execute your custom tool against required files
run usual build target (or whatever target you normally use)
Edit
E.g. in a .csproj file you could define the following:
<Target Name="buildWithCustomTool">
<!-- Exec your custom tool -->
<Exec Command="your command" />
<!-- Call the build target which will run as normally -->
<CallTarget Targets="Build" />
</Target>
Hope it helps,
Ivan

Related

automatic build and deploy fails with build failure on jazzhub

I am trying to use the feature of jazzhub (IBM DevOps offerings) of automatically build and deploy on Bluemix. I have used Eclipse plugin for Jazzhub to check in my code to my project. However automatic build always fails with the below type of error.
using .gitcredentials to set credentials
Checking out Revision a0b1e7c78b02e82ad210bc369cdd633212cb544f (origin/master)
First time build. Skipping changelog.
[47f4a135-016e-4a75-bb42-f9a9fda6df05] $ /bin/bash /tmp/hudson3124921405781328608.sh
Buildfile: build.xml does not exist!
Build failed
Build step 'Execute shell' marked build as failure
Connecting to https://P90JEN01.sl.jazz.net:9444*
I am able to build and deploy the same code base from Eclipse directly to bluemix. My understanding is that DevOps service create build.xml file automatically if It does not find one. The document says it
"A project relative path where the build scripts are found and executed. The project root will be used if empty. A default build script (e.g., Ant build.xml file or Grunt Gruntfile.js file) will be generated and delivered to your source control system if one is not found. You may need to edit the generated build script to fit your needs".
Can anyone help me here? how to get pass this error and make a build successfully deployed ?
I believe we may need to create build.xml if you are using ant script:
http://thoughtsoncloud.com/2014/10/create-deploy-stand-alone-java-application-ibm-bluemix/
"The next step is to create the script to build the code. In this example, I created an .ant script. You can write in the language of your choice from the options supported in Bluemix. Create a file named build.xml and write the .ant build script."

Using TFS Build to Deploy Console Application with Continuous Integration

I have a solution that contains a number of projects. Some MVC Web Applications, Some Class Libraries and some Console Applications.
For the Web Applications we simply used Publish Profiles and created TFS Builds referring to those profiles for building deployment packages. We then used those to deploy the web apps.
How can I configure the Build Definition to give me the same results for my console applications?
The desired result here is to try and work towards automatic deployments using TFS and Release Management.
Update:
Ok, It seems I need to explain myself better.
We use TFS (MSBuild) to build the project. By simply "checking in" the code, it triggers our build which builds the project and creates a nice Website_Package.zip file in the drop folder.
What I am looking for, is for MSBuild to do the same for my Console Application. ie. I want it to produce a "ConsoleApp_Package.zip" file and dump it into my drop folder.
You can use the Zip task from MSBuild Extension Pack at http://msbuildextensionpack.codeplex.com/.
See http://www.msbuildextensionpack.com/help/4.0.8.0/index.html for an example.
You should just build, using MSBuild task, filling the Project with your console app .csproj and leave MSBuild Arguments empty.
Then you use a Copy Files task to get your files from bin folder to staging directory.
Example:
Source Folder: \bin\$(BuildConfiguration)
Contents: **
Target Folder: $(Build.ArtifactStagingDirectory)
After that you can add task to zip the files from staging directory.

How to run junit tests at build time in netbeans and jenkins?

I'm trying to set up a project to run junit tests at build time, so that every member of the team and the Jenkins build server runs the tests when it builds.
I believe we have set up a fairly standard webproject in Netbeans, but I can't seem to find anyone solving this problem on stackoverflow or google.
How would you go about doing this?
Go to file: /nbproject/build-impl.xml and fidn the dist target. It should look like this:
<target depends="init,compile,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
Copy paste it into /build.xml, and add the "test" target into it:
<target depends="init,compile,test,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
This was in Netbeans 7.3. It now builds and runs the tests on every build, also on the Jenkins build server.
Never modify your build-impl.xml! Netbeans regenerates this file when you perform any changes to your project.
The better approach would be to modify your build.xml and add a post-jar task:
<target name="-post-jar" depends="test"/>

ScriptSharp compilation with NAnt script

We've recently added the excellent script# to our project. Currently we have it so that our VS build simply copies the compiled .js file from the output directory to the scripts directory of our web app.
We've decided to make it a permanent feature and so would like to make it so that the .js file gets generated as part of our web build NAnt script to ensure that it's always up to date. Is there any way to do this nicely or do I need to call MSBuild from my NAnt script specifying the .csproj file to run the compilation?
Thanks
Stu
This isn't likely the full answer (given I don't have experience with NAnt), but I'll offer it anyway, as it may help.
A script# csproj is very much like any other csproj relying on msbuild. If you've got some way to integrate other msbuild projects into your NAnt build script, the same model should ideally apply to script# projects as well.
In the version of script# that is in the github repository, a web project can add a reference to a script# project (thereby becoming dependent on the script# project), and include an msbuild deploy task, that will copy over scripts from the built script# project into the web project. You can see this in action in the Todo sample (https://github.com/nikhilk/scriptsharp/tree/cc/samples/Todo)

NAnt script for running multiple test assemblies

I'm just getting into TDD, and from looking around, the general concensis seems to be to have a one to one mapping from a code project to a test project. My question is, if you follow this route, and have multiple test assemblies, what is the best way to run these as part of an NAnt script? If it makes a difference, I am using NUnit as my testing framework.
You can create a "test project" via the NUnit GUI, and save it to a file. In the GUI, you can add to the project the test dlls, which in turn reference the ones under test.
You can then pass that file to the NUnit console from within NAnt. e.g.
<property name="nunit.output" value="${dir.reports.nunit}\nunit-results.xml" />
<property name="nunit.input" value="proj.nunit" />
<exec program="${dir.tools}\nunit\bin\nunit-console.exe" failonerror="true">
<arg value="${nunit.input}" />
<arg value="/xml:${nunit.output}" />
</exec>
This way, NAnt need not know about the test dlls, just the NUnit project that contains that information.
I'd suggest the best way to go about this is to compile both projects from NAnt individually using the CSC command referencing each project file (csproj) rather than the solution. Then use the nunit-console command (as a separate Nant task) to execute your tests.
Whether you have one build large script/file that does this or separate separate ones for each project or task is up to you (or how complex your projects are).
The way I have my team's builds set up is that I have one 'master' build script which calls into other build scripts to perform specific tasks. For example 'master' calls 'compile' and then 'test' (passing in the results of the 'compile' script appropriately). This way the compilation of my core project is separated from the automated testing.