Skip to main content

Notifications

Announcements

No record found.

TFS Build and NAV 2018

Hi team!

 Today I tell you about my home experience of building NAV 2018 database from Bitbucket repo on Team Foundation Server.

UPDATE

The article with screens

 Prerequisites:

  1. SQL Server 2017 RTM (not named, default instance);
  2. Dynamics NAV 2018;
  3. Team Foundation Server Express (not VS Online, Not Azure DevOps, not TFS online, just TFS on-premise on your laptop);
  4. Scripts made by Waldo (https://github.com/waldo1001/Cloud.Ready.Software.PowerShell)

Prepare repository

A repository should contain objects to build in TFS, for the experiment I made a repo with one table.

Folder structure:

  1.  .git;
  2. .vscode;
  3. App
    1. BaseApp;
  4. Scripts
    1. Build
      1. 1 - New Nav environment.ps1;
      2. 2 - Update objects.ps1;
      3. 3 - Compile.ps1;
      4. 4 - Remove environment.ps1.

Prepare scripts

Run your build scripts step by step and test the results.

Remember that TFS will not interact with a user, so use -Force and -Confirm:$false keys.

I have installed Dynamics NAV 2018 on my laptop, I don't need to reinstall it on every build, as I keep SQL server installed. My build plan steps:

  1. Setup NAV environment (service + database, names hardcoded:), import licence);
  2. Update objects (generally in would import all object from the App\Baseapp directory, but it contains only one object, so I will import only one table);
  3. Compile all uncompiled objects (better to compile in parallel jobs then recompile all the rest, but for the test, it's enough, you can find how to compile in parallel jobs on MSDN on you can use Waldo's script from the repo);
  4. Remove NAV environment.

The real build plan will contain also testing, reporting results and making some artefacts like FOB files.

 I prepared different files for every stage, so I can easily change process in build.

 Setting up environment:

Import-NAVModules

New-NAVEnvironment -ServerInstance 'Nav2018Test' -DatabaseServer 'DESKTOP-O3Q6HQG' -DatabaseInstance '' -Databasename 'Demo Database NAV (11-0) 2' -BackupFile 'C:\Users\chere\Files\NAV DevOps\NAV 2018 SCM\backup\Demo.bak' -LicenseFile 'C:\Users\chere\Files\NAV DevOps\RD Leasing ZAO 5171150 NAV2018.flf'

 

Update objects:

Import-NAVModules

cd .\App

New-Item -ItemType Directory -Force -Path .\temp

Get-Content .\Baseapp\*.txt | Set-Content .\temp\all.txt

Import-NAVApplicationObject -Path '.\temp\all.txt' -DatabaseName 'Demo Database NAV (11-0) 2' -DatabaseServer 'DESKTOP-O3Q6HQG' -Confirm:$false

Compile:

Import-NAVModules 

Compile-NAVApplicationObject -DatabaseName 'Demo Database NAV (11-0) 2' -DatabaseServer 'DESKTOP-O3Q6HQG'

  

Remove NAV environment:

Import-NAVModules

Remove-NAVEnvironment -ServerInstance 'Nav2018Test'

  

Easy.

Prepare job

Once having your scripts ready, it's time to have TFS job. TFS use jobs to execute build actions, so you have to download, configure and run the job.

 In your TFS page go to Agent -> Agents queue, then click download.

Once downloaded you can configure your agent.

Open the downloaded folder. Run config.md file and specify all the information.

Then run the run.cmd file.

Don't forget to use administrator mode for every file.

 It will connect to specified TFS.

Prepare build

Create a project in TFS, connect it with the repo. Skip, if you have a repo on different service.

Create a building plan.

Connect the build with your repo. I use Bitbucket repository, so I had to connect it with my TFS. Different TFS versions are connected in different ways, it's easy to find in Google. I linked my Azure DevOps and TFS with one Bitbucket repo:

Azure DevOps:

 TFS on my laptop:

Go to build definition -> repository -> manage:

Select Repository type = External Git

Push the button "Manage" in line Connection.

Specify name and connection URL

 

Easy. Every build will place your repo to a temp directory on a laptop (server) during the build process.

 

Then you have to specify your build definition.

Go to build specification page in TFS, create a build and specify steps using PowerShell modules.

Use relative paths to scripts.

For example, I have the script file "1 - New environment.ps1" in the directory "repo\Scripts\Build", I specified the path as you can see on the screen (Path: Scripts\Build\1 - New environment.ps1).

 

That's it.

RUN

Run TFS agent (run.cmd file) as administrator.

Run your build on TFS.

Build Agent will handle all the work.

I don't know how, but my Bitbucket repo knows about the last build (it was hard to link the screen here, so just believe)

 If I click on the green circle if shows me that the latest build status and link.

The link shows Azure DevOps build instead of TFS, but I'm sure that the latest build was a TFS build, not Azure DevOps. Seems like Azure DevOps smarter than my desktop TFS and I didn't manage TFS enough:)

 

Thanks, Waldo for publishing the scripts.

It would be hard to have the results without his work:

https://github.com/waldo1001/Cloud.Ready.Software.PowerShell

Comments

*This post is locked for comments