Using TF command-line get latest, how do I run SonarQube analysis only if new code has been checked-in? - batch-file

I use a BAT file to run TF command-line get latest and then call the Sonar runner BAT file to run analysis on the latest code.
I have automated this every hour using Task Scheduler.
I want to run Sonar analysis only if TF gets new code, else it should skip.
How do I achieve this? I tried searching for exit codes, but nothing tells me if any new code was fetched.

Visual Studio Team Services or TFS 2015+
You can configure a build to be triggered on Continuous Integration (CI), i.e. whenever changes are made, the build is triggered. A build can be whatever you want, from invoking a proper msbuild / mstest and SonarQube task or doing your own stuff using cmd / powershell / bash.
To learn more about integrating SonarQube analysis with TFS Build see: https://blogs.msdn.microsoft.com/visualstudioalm/2015/08/24/build-tasks-for-sonarqube-analysis/
TFS 2013
You can configure a XAML build to run on Continous Integration
Through scripts
Continous Integration builds are the recommended way of running logic when a change happens in your code. However, if you'd like to use "tf get" - you could capture the output of "tf get" and if it matches "All files are up to date" then do nothing, else trigger the SonarQube execution.

Related

Automating Tortoise SVN Update Fails While User Execution Succeeds

I have a few files i want to make sure I keep up to date using Tortoise SVN. I've used commandline and also created a batch file and both run successfully when I user-execute them.
However, when I use Windows Task Scheduler to try and schedule an automation for the batch script, it doesn't run successfully; it just hangs and runs endlessly. The log file looks just the same whether using the automation or not. That said, I have to manually end the automation in task scheduler and then run an SVN cleanup command to remove the locks that remain on the file from the incomplete task.
What is causing this, and how do I make it so that the automation successfully runs and doesn't have the file-locking problem?
My back script's code is below:
svn update --accept theirs-conflict C:/MyFolder/myfile.R
For transparency, I've tried changing the option 'theirs-conflict' to other settings (and removing it completely). The symptoms are the same in every scenario.

background process launched by TFS is killed when switching to next step

I have some trouble keeping alive a background process when launched by TFS.
Usually I use a batch that launch a java server (new window), as long as I keep this window open it works properly.
C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In order to make my process automatic, I include this in TFS. In the step I call a batch that contains the following:
cd C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk // necessary to find the batch
start C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\server.bat
In my task manager, I can see in background tasks that java is launched (no new window is opened), exactly as it behaves when launching directly the batch. But after a few seconds, when TFS switches to the next step, it stops.
Then the next step carries on but fails as it requires the server to be launched.
Is there a particular way of doing it in TFS ?
thank you
Alexandre
It's suggest to launch the .bat file from a relative path not directly use cd to hard code the path.
Also recommend you to use Run Batch File task not Run Command Line task to launch the .bat file.
According to your description, seems you are using a run command line task in your build pipeline. Then run the command under the working directory c:\Build_work\5\s, the command cd to C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\ on the build agent, find the server.bat, run the server.bat.
First check if the .bat file is located at the path you are specifying on the build agent. Not sure if the bat file have to run under C:\Users\TFSService\mbs-iot-sdk\osgi\bin\vms\jdk\, guess you are also hard code the path in your server.bat file. Suggest you change all the path to relative path, you could use some built-in variable in TFS.
As for your workaround in comment, seems you want to chain builds in TFS. The official docs literally say "not yet" and have a uservoice in planed. However you could use some workaround, such as create or use other's customize extension (use rest api) to call another build. Detail ways please refer huserben's answer in this question: How to chain builds in TFS 2015?
Note sure you have to go deep into this area for your original issue. Just add some related info in case you are interested or need.
Well,
Just in case someone else goes through the same kind of issue, I found a workaround:
I wish to mix different command line steps, some of them launching Python scripts:
I have one step for launching the server that is required for my testing tool, one step for my testing tool and one Python step for differential testing
I realized that I could embed everything in a Python script.
It can handle server launching process in a separate window (with subprocess), launch my Python part and launch another process for my validation tool.
I have to test the whole chain but, at least, I solved my problem of launching a background process and detach it from TFS

How to run multiple SpecFlow scenarios using batch script?

I have visual studio 2015 professional edition and in my project there are many feature files and they contain several scenarios of specflow.
I want to run some specific scenarios(having same tag name) of different features using a batch script. So, How do i do that?
It depends which test runner you are using and which flavour Specflow generates your tests in. Basically you write a batch script to call a console tool of your test runner to run the tests. Assuming you are using NUnit you can run them with NUnits runner as described in the documentation other runners will require other stuff
I got the solution, to run specific scenarios we will use common tag name for those scenarios and use the tag in the batch file.
Ex: Features /include:
And after that we use the tag on another batch file(Ex: set arg1=%1). There you initialize the variable for the project. Set the packages for the project and debugger-location.
Then use it in the nunit console and run the .dll file
Ex: nunit-console "%DebuggerLocation%\%Namespace%.dll" %arg1%

Automate Build script from Batch to MSBUILD/NANT

I am trying to automate a build process for a C# (vs2008) solution.
The build script is written in a Batch script which I want to change. We use Clearcase as the CM system. I have searched some tools such as MSBUILD, NANT.
Any suggestions which is a better solution like a sample script in MSBUILD and NANT?
I have not seen any sites where MSBUILD and NANT is documented well or any good tutorial about each task description.
Where I can learn MSBUILD or NANT either of them and write script from scratch?
There is a third way which I prefer. You can also use devenv.com. It's faster than NANT, doesn't require NANT bins and works on any machine with VS installed. You also avoid possible errors with MSBUILD (http://support.microsoft.com/kb/964125).
Just use %path_to_devenv.com%\devenv.com "%path_to_sln" /<buildoption> BuildConfig
In my case it's
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com "C:\Projects\XYZ\xyz.sln" /rebuild Debug
This way it's guaranteed that your project will be build exactly the same way as it's being built in Visual Studio.
EDIT:
Now that we know how how much there is to do, I'll try to give an outline how you can setup the whole system for automated build controll.
Set up your repository (I hope this is already done - tell me if not)
Install and set up Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins) including users, ClearCase-Credentials, plug-ins for ClearCase, MSBuild, etc. (all of them can be found in the Jenkins plug-in interface) - this is the biggest peace of work
Create and set up a new project in the jenkins interface (name, working directory, etc.)
Tell jenkins to use source code management (e.g. subversion module), enter the ClearCase repos to use, set the desired behavior of the source code management
Set a build trigger (I recommend checking the source code management each minute: * * * * *)
Add a build step and select "Build a Visual Studio project or solution using MSBuild" - this option should appear after installation of the MSBuild plugin (https://wiki.jenkins-ci.org/display/JENKINS/MSBuild+Plugin)
Set the path to the .sln file (you have checked it out from your repository)
Add more optional arguments if desired (eg /p:Configuration=Release or Debug or whatever http://msdn.microsoft.com/en-us/library/vstudio/ms164311%28v=vs.110%29.aspx)
Play around untill it works
Btw., I recommend to put all external dlls into your repository.

How can I start an RTC build via the command line?

The build definition is created but in order to automate the build process I need to start the build via the command line.
How is this done ? Reading the doc on the scm command line client this does'nt seem to be described :
http://pic.dhe.ibm.com/infocenter/rtc/v1r0m0/index.jsp?topic=%2Fcom.ibm.team.scm.doc%2Ftopics%2Fc_scm_cli.html
I don't think scm is involved at all for launching a build.
You check out the Java API: See "Automated Build Output Management Using the Plain Java Client Libraries".
Or, you can use the JB Toolkit, and use a task like requestTeamBuild:
The requestTeamBuild task requests a build by using a specified build definition.
There must be an active engine that supports the build definition in order for the request to succeed.

Resources