TFS tips #2 – CodedUI with testagent

💡 This post is part of my TFS tips where I write about how we make the most of TFS (on premise)

During release in our CI/CD we want some codedUI tests to run. In TFS we have the “Visual Studio Test Agent Deployment” and “Run Functional Tests” steps but some extra work is needed to get the tests running every time.

Manual

Since we use the same dedicated machine for every codedUI test the setup is done manual. There are two things that need to be configured:

  1. screensaver timeout, make sure it is long enough (10 min+) or disabled
  2. autologon (sysinternals), provide the credentials and after every reboot this user is automatically logged in.

Release

The first step in the release definition will reboot the codedUI machine. Then the artifacts are deployed to the first environment (during which the codedUI machine is rebooting) When it is time to start testing the codedUI machine is done booting and the autologon makes sure it is able to interact.

Posted in Development, Tooling | Tagged , , , | Leave a comment

TFS tips #1 – Install Java runtime on local server

💡 This post is part of my TFS tips where I write about how we make the most of TFS (on premise)

We are currently working on a project that needs the Java runtime to be installed on our local servers. As lazy developers we want to script this once and let TFS Release handle it from then. This way we can expand our OTAP or scale out in productie with ease.

Artifact

The default proces of Release is get agent from pool, collect artifacts, install artifacts on target. So the first thing we did was add the Java runtime installation to an artifact on the build.
The build makes one archive (zip) from the installation files and scripts. That zip file is published as an artifact on the server. This way everything is available to TFS, no hassle with access rights to fileshares.

DSC

Our standard for script installation (and checking) of software is Desired State Configuration.
The complexity with this DSC is the required reboot after the Java runtime installation. There is a way to do this with DSC by allowing the DscLocalConfigurationManager to reboot if needed and to signal that a reboot is needed.
For this we create one Dsc script and one powershell script that applies this Dsc. The important part of powershell script is below:

# create mof
DscJavaServer -ConfigurationData $ConfigData -Verbose
# allow the server to be rebooted
Set-DscLocalConfigurationManager .\DscJavaServer -Verbose -Force
# apply DSC (install java if needed)
Start-DscConfiguration DscJavaServer -Wait -Verbose -Force

The contents of the Dsc file:

configuration DscJavaServer
{       
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
      
  Node $AllNodes.NodeName
  {
    Write-Verbose "Configuration for $NodeName"
    Write-Verbose "Installation files should be in $DeployLocation"
 
    # This allows the reboot
    LocalConfigurationManager
    {
      RebootNodeIfNeeded = $true
    }
 
    Script Java
    {
      GetScript  = { return @{} }
      TestScript = { return Test-Path 'HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment' }
      SetScript  = {   
        $installer = "$($using:Node.DeployLocation)\jre-8u144-windows-x64.exe"
        Start-Process $installer -ArgumentList '/s' -Wait
        # signal reboot
        $global:DSCMachineStatus = 1
      }
    }   
  }   
}

Release

The release definition will push the artifact to the target server, unpack the archive (zip) and execute the powershell script.
Now we have a release pipeline that can make sure the Java runtime is on a target machine. If it is not the installation will be done including the required reboot.

Posted in Development, Tooling | Tagged , , , | Leave a comment

SDN event June 2018 – My scrum experience

The SDN – Software Development Network – is a special interest group for dutch developers. Four times a year they organise an event where people present and talk about their passion.

As a member of the SDN you are aware of the latest developments. You are part of a network of professional developers who assist each other in word and deed. This means there is a technical helpdesk at your fingertips so you can book considerable time savings in solving problems.
sdn.nl with Google translate

I’ve been working in a scrum team for two years now at the Statistics Netherlands. Today I shared my experience with the audience. Slides direct download (dutch).
Eric presenting

Slides and recordings of all talks available at SDN.nl.

Posted in Conference | Tagged | 1 Comment

Adding SonarQube to TFS build

We’re moving toward DEVOPS with our team and want to automate code quality checks. Another team already installed a SonarQube server for their python development and advised us to try it for our dotnet development. Now we know why the other team is stocked about SonarQube. We are sure you will be setting this up for your own team when you see how easy the setup is and the huge quality gain it brings.

Service Endpoint

First add a new service endpoint to your TFS by going to settings > services. Put in the url (root of the sonarqube server: http://your_sonar_server) and your token (generated in sonarqube, hover over the icon at the end of the input) and give it a suitable name.

Build

After installing the sonarqube build tasks on TFS and adding javaruntime to your build agents you can add sonarqube to your builds. There are three tasks you should add: prepare, run and publish. Only the first task (prepare) needs to be configured to the service endpoint you created before. The project key and project name are up to you and will be created if they don’t exist (like the first time you run the build) We’ve set the project version to the buildnumber which is not the case in this screenshot.

Report

Now queue a build and watch sonarqube do it’s magic in the logging. You’ll notice the actual analysis is done on the build agent, not on the sonarqube server. This is why you need the java runtime on the build agent. After the publish you can browse to the sonarqube server and find your project in the list of projects. Open the details page and find something like below:

The bugs are mostly caused by not validating parameters like assuming not null.
Vulnerabilities are about known security issues.
Code smells tell you about to much nesting of to much if statements.
Code coverage from unittests is reported.
Duplication reports duplicate code.
Everything combined gives you the technical debt.
You can setup rules (or use the default) that determined the quality gate result. Make sure you’re in the green :mrgreen:

References

SonarQube VSTS/TFS documentation
SonarQube build tasks

Posted in Tooling | Tagged , , , , | 3 Comments

Powershell extension method

We are testing our Powershell Module with Pester. Since the data is some sort of graph we need to work with indexers / lists all the time. After a small brainstorm session we decided on an Extension Method approach.

Reading the post Extension Methods in Windows PowerShell from Bart de Smet we started to develop. After some attempts we ended up with an XML containing the scriptmethod we needed. Important tip is to handle the $args in a special way: assign to local variable to prevent getting lost …

<?xml version="1.0" encoding="utf-16"?>
<Types>
 <Type>
  <Name>Company.RootNode</Name>
   <Members>
    <ScriptMethod>
     <Name>GetById</Name>
     <Script>
      switch ($args.Count) {
       1 { $req = $args[0];[System.Linq.Enumerable]::First($this.Children, [System.Func[Company.Node,System.Boolean]]{ param($x) $x.Id -eq $req })}
 default { throw "No overload for Uses takes the specified number of parameters." }
      }
    </Script>
   </ScriptMethod>
  </Members>
 </Type>
</Types>

You can load the extension method into powershell with the following command, where RootNodeExtensions.ps1xml is the name of the file containing the xml

Update-TypeData -prependPath RootNodeExtensions.ps1xml

Now the RootNode has the extension method GetById, so we can use $root.GetById(“12345″) that returns the first node in the Children property that has the Id==”12345” or throws an exception. Sounds like testing 😉

Posted in Development | Tagged , , , | Leave a comment