Execute Batch File After Tfs Build Manager

This article will demonstrate how to integrate SonarLint with Visual Studio 2015. SonarLint is a tool for managing code quality. We will also see how to integrate SonarQube with TFS build by creating a build definition.

It is essential to maintain quality while writing code. Visual Studio provides a lot of tools to help maintain the quality of the code.

Apr 28, 2010. After the “Run MSBuild for Project” we will add the logic to copy the files that the user have configured to copy. Open the toolbox and. I set up the TFS 2010 build but my robocopy doesn't do anything even though my work flow got set up based on how Ewald shows on the forum. If you could be help me,. In this article, you will find information regarding the newest release for Team Foundation Server 2018. Click the button to download. To learn more about Team.

Execute Batch File After Tfs Build Manager

Some of these tools are (to define rule sets for code), Code Metrics (to find maintainability of code), (to make debugging easy),, IntelliTest, Web Performance Test, and Load Testing. All these tools help make the life of developers easy.

The better the quality of code, the less number of bugs which in turn boosts up the overall productivity. In this article we will be talking about one of the Open Source tool named Sonar. Also read: Overview of SonarQube SonarQube is an open source platform developed to manage quality of code. It covers various parameters of code quality like duplication in code, lines of code, unit testing, coding rules, complexity and bugs.

It supports 20 different programming languages like Java, C#, COBOL, ABAP, PL/SQL etc. With the help of plugins. There is a plugin named SonarLint available for Visual Studio. You can download it from Visual Studio Gallery. SonarLint provides on the fly bugs reporting, and quality issues for C# and VB.NET code. SonarQube can be downloaded from this.

You need to have Java Environment installed on the machine. Once downloaded, unzip the files and run the batch file named “StartSonar.bat” (from folder sonarqube-5.6.1 bin windows-x86-64) to start the server.

The default port number is 9000. Once the server is started, you will see the following screen in the browser. Figure1: SonarQube Dashboard You can establish a connection to the SonarQube server and bind the Visual Studio solution to the SonarQube project. We will also discuss how to add build tasks to use code analysis for TFS build using Visual Studio Team Services (VSTS). Adding SonarLint to Visual Studio 2015 I am going to discuss how to add SonarLint in Visual Studio 2015 and use it while creating a desktop build (analyze the Code along with Build). Later I will add the solution in the source control and use the tasks for SonarQube which will provide us with reports for managing quality along with TFS build. Open an existing solution which has some code to perform code analysis.

Add SonarLint to Visual Studio using Tools – Extensions and Updates Figure 2: Download and Install SonarLint for Visual Studio Like Static Code Analysis, the new ruleset is added in Code Analysis tab. Go to Properties for Project and select the tab for Static Analysis to find out different rules for SonarLint. Figure 3: Rule set for Sonar 3.

I have changed some of the rules to error and have tried to apply to the solution. Right click on the solution >select Analyze and select “Run Code Analysis on Solution” 4. As the rules have been modified, I get an error instead of a warning Figure 4 & 5: Rules not followed via code 5. We can bind the project to SonarQube and an existing project there. Figure 6: Connect to SonarQube Server 6. While connecting, you need to specify the url for SonarQube server.

In my case I am using my machine as a server, so I am using localhost 7. After you connect to the server, you can bind the project and view it in SonarQube. The following report shows the Code details about my project and the Dashboard looks as follows Figure 7 & 8: Reports published on sonarQube Until now we saw how to manage code quality with Visual Studio. Now let us create a server side build and find out how the build tasks can be used in it. Using SonarQube with TFS Build Let us now create a build definition using Visual Studio Tem Services (VSTS) and use SonarQube with TFS build. The aim of this article is not to go into details about how to analyze the report generated by SonarQube, but how to generate it using VSTS and Visual Studio.

Execute Batch File After Tfs Build Manager

Once you integrate and know how to obtain the report, you can always go into the details of the parameters provided. SonarQube can be installed on any machine in the network. It should be accessible from the machine on which the build agent is running.

Choose Legacy Windows for smaller footprint. Once downloaded, unzip it in the specified folder. I have used c: Agent folder for unzipping. Figure 9: Agent folder Run the command file ConfigureAgent.cmd and follow the steps. You need to provide the name of the agent, Team Foundation Server url, whether to configure the agent against the Default Pool or not, the working folder for the agent and finally if the agent is to be installed as a Windows Service or not. Ensure that you are running the command with administrative privileges. Once the agent is configured we can view it from Control Panel – VSTS name - Project Name – Agent queues tab.

Creating Build Definition We need to create a build definition with the 2 Build Tasks provided for SonarQube integration. Before creating a build definition, download and configure the Build Agent. I am going to use the Default Build Agent as my SonarQube is running on the local machine. You can download the agent by selecting Download Agent link from Agent queues (by selecting control panel for VSTS) 1. Create a new Team Project or use existing one and add code to it. Create a default build definition for Visual Studio template.

Add 2 tasks for SonarQube to it Figure 10: Build Tasks for SonarQube 4. Configure the task for Begin analysis. We have to point it to our SonarQube server. Select Manage for SonarQube Endpoint and we will be re-directed to creation of new Service end point. Select a new Generic Connection and provide details for Server.

Enter the name for the endpoint and the connection URL. The configured task looks as follows Figure 11: Configure Build analysis task Project Key is with respect to the project you are performing analysis on.

Project Name is the project being analysed. Project Version by default takes 1.0. You can change it if required.

You can even use it as the BuildNumber. Once the Build Definition is ready, ensure that it is using Default Agent and not the Hosted (default for VSTS) as our SonarQube server is on local machine.

Once the build is successful, we will get all the warnings for the SonarQube ruleset. Figure 12: Build Summary with Warnings 9. The detailed report can be seen by clicking on the link.

You can see that the Quality Gate Passed is shown in the report. The quality gate can be changed by using the Advanced tab from the build task for analysis Figure 13: Change Quality Gate Setting 10. If there are test assemblies and you have also enabled Code Coverage, the build will also show Test Results along with Code Coverage as follows Figure 14: Build Summary with Test Results and Code Coverage Create Quality Gate for SonarQube Finally I will create a new Quality Gate for SonarQube and apply it to the project. The default quality Gate can be found at Quality Gate tab from SonarQube Figure 15: Default Quality Gate We need to login with administrative privileges in order to create a Quality Gate.

The default credentials are User name as admin and password as admin. Once you have successfully logged, you can create a new Quality Gate, provide the name for it and add various conditions to it. The conditions can be for Complexity, Code Coverage, Unit Testing, Documentation, Duplication, Size etc. After creating a new Quality Gate I set it as default and again Queue the Build. My Quality Gate failed because of the conditions I have set. You can also see that the build has partially succeeded.

Figure 16: Quality Gate Failed Click on Detailed Report and further it shows that the Code Coverage is 33.3% because of which the Quality Gate failed. Conclusion In this article we discussed how SonarQube can be used in Visual Studio 2015 to manage quality of code written. It is an Open Source tool which can be integrated with Visual Studio. We also discussed how the build tasks can be added to TFS build and integrated. We also discussed how to create a new Quality Gate and make use of it with the build task.

In this post, I want to show you some of the new features and changes in the 2013 version of Team Foundation Build. In my opinion, there are some nice little things that will make your life much easier! TFVC and Git With TFS 2013, you now have the possibility to create a Team Project using Git as version control system. This will create a central GIT repository where you can push and get files from/to. Visual Studio 2013 will offer you a great GIT experience. You can find some information about the GIT story.

And of course, you can now also build the code you store in a Git team project and you can generally do everything you can do like with code stored in a TFVC team project. If you create a new “ Build Definition” (Team Explorer – Build – New Build Definition), you have to option to get your sources from a TFS Git repository. A nice thing is that you can also get sources from whatever Git repository. Meaning that you can also use other Git services on your build system. The only limitation you have there is the fact that you will not have the CI and Rolling build functionality. One notable exception for Git builds: you cannot define a gated check-in build in a Git team project.

Copy build output to the server Just like in Team Foundation Service, you now also have the possibility to save the build output of your builds to the server. Previously, with TFS 2012, you also had the option to store your outputs on the server, but this “server” part was actually the version control repository. That option came with some drawbacks.

For example, users had to be sure that they cloaked the drops folder or the syncs would get increasingly long. In addition, each build drop generated multiple new check-ins, which affected the history and possibly triggering unwanted version control notifications. In your build definition, go to the “Build Defaults” and select “ Copy build output to the server” If you now look to the build overview of a completed build, and click on “ Open Drop Folder”, you will be redirected to the web access.

There you will have a link called “ Download drop as zip”. Improved build diagnostics You now have the ability to view the build diagnostic logs in the TFS Web Access.

You can also download your logs as a zip. Being able to view the detailed diagnostics log is a handy feature that you can use for easier build debugging regardless of where you are dropping the build outputs. Beyond just viewing the log, you easily jump from one error to the next.

In my opinion, that’s quite a nice addition, mainly because it gives you some more information than the build report in Visual Studio gives you. It will for example s how you the sequences in the build workflow, it will also show you what the download size of your sources is, where the sources are stored, It even goes a little step further.

If you click “ show properties”, it will show you all parameters from your build. In TFS 2012 (and older), you were required to set the logging verbosity higher than “normal”, but using the new Build Process template, you don’t have this option anymore. “Default” Build process templates A great new feature in TFS 2013 is the usage of “ Default” build process templates.

Note that the term “Default” is not related to the name anymore. What I mean by that?

Well, in TFS 2012 and prior, your Build Process Templates were stored in source control. On one hand, that’s good, because you can easily change or modify the templates and save them somewhere in Source Control. But on the other hand, that’s quite a XAML overload if you have a dozen Team Projects with builds using a default, non-modified, Default Build Process Template.

Braudel Capitalism And Material Life Pdf Download. In TFS 2013, you now have 2 real “Default” Build process templates that are not stored in source control. (well, not directly). There’s one template for TFVC and one for Git. You cannot modify this “global” templates directly. In a next chapter, I’ll talk about why you will probably not change the default templates. You can of course modify this template.

You can click the “ Download” link, modify it, and add it to source control (like the “ old” way). You can then select this modified source control based template by clicking on the “ New” button.

Post- and pre-build scripts When I’m at a customer and they need some “ custom” build-related things, I generally discourage them to modify the build process templates. (I’m sorry!) The reason for that is most of the times, they want to do some XCopy things, start/stop an IIS, modify a file,. You can indeed modify the Build process template by adding some activities, but in general, it’s a difficult process for people without any Workflow experience. It’s also a fast and heavily changing process meaning that your build process template will require lots of changes. What I did (up until now) was adding one additional activity to the template, where I had the ability to execute a PowerShell script including a step to pass all TFS related parameters to the script. Well, good news, we have this by default now! In the build definition wizard, you can now select either a batch or a PowerShell script.

You even have the possibility to choose when you want to execute this script. You have 4 options: • Before MSBuild compiles your code • After MSBuild compiles your code • Before the test runner • After the test runner In this example, I added a PowerShell script called “ Deploy.ps1” (which is stored in Source Control).

It contains a simple write-host. If you look to the build log, you will see: That’s great, but what if we need some information about the build itself? Like the drops path, the path where the sources are located, Good news, those variables are available for you! They are stored as environment variables. Let’s assume that I want the name of the Build definition. Well, in my PowerShell script, I add the following. Write - Host “ The build definition name is “ $ Env: TF_BUILD_BUILDDEFINITIONNAME And you will get the following result: You can get Simplified Build process template If you however decide that you still need to put your own secrets in your build processes, you will now be happy to see that the overall structure of the template is way easier to understand.

Let me show you how it looks like now: You can now finally get to the right piece without struggling through the never-ending-collapsing XAML. Your process will also have a much cleaner look: So, this were some of the new TFS Build features and improvements. The things that I like most are the pre/post build scripts and the ability to run TFS build from whatever Git repository you want.

What do you think? 29 Comments • Bhushan Gawale This is awesome. How about integration of Continuous Deployment with Windows Azure Cloud Services? Are there any upcoming features in build system to achieve that as well?

• This looks very nice. One thing I don’t like about the default build template though is that it associates a build to the work item before actually trying to do the build, so even if the build fails the work items get updated. This was a sore point for our QA team as they would assume that if they see an “Integrated In Build” version that it meant the bugfix/feature was actually in a build and ready to be tested; so I modified our build template to make this one of the very last steps to complete, and only if the build passes successfully. The Git integration and Pre/Post build scripts are a very nice addition, as I would much prefer to work in PowerShell than Workflow (as long as it is still easy to call the TFS activities from PowerShell). I’m wondering how easy is it though to pass custom parameters that we add to our build templates to the Pre/Post build scripts? Also, your link to the list of TF Build environmental variables accessible from PowerShell is broken. • Alexander Vanwynsberghe Thanks Daniel, I quickly fixed the broken link!

• Aghilas Yakoub Hi Alexander, thank’s very good article about process, you have also new activities in the build process if you are interested, • Alexander Vanwynsberghe Thanks for sharing Aghilas! Any chance on an English version?

• Durga Prasad How do I configure environment variables? • Alexander Vanwynsberghe You cannot really “configure” those environment variables.

TFS Build will pass the correct value to the variable. You can of course use the script arguments to pass additional arguments to your script. • Durga Prasad for some reason I am getting below error when run the script.

Script is: Write-Host “Hello Poweshell script.“ $testdata =“The build definition name is “$Env: TF_BUILD_BUILDDEFINITIONNAME $testdata >>“C:temp1log.txt” Error: Unexpected token ‘Env:’ in expression or statement. At C:Builds1Training PortalSystem TestsrcBuildProcessTemplatesscriptssy stemtest-postbuild.ps1:3 char:48 + $testdata =”The build definition name is “$Env.