Lesson 18 of 18

Invoking FinalBuilder From TeamCity

Duration: 8:20 Watch on YouTube (external link, opens in new tab)

Markdown version

In this lesson

Roy Osherove runs a FinalBuilder (external link, opens in new tab) script from TeamCity: he puts the demo folder in a git repository, with the FinalBuilder zip file (FBZ) at its root so that the build does not need to know the structure of the application, and creates a TeamCity project with a VCS root that points to it. A build configuration with a PowerShell build step calls FBCmd.exe on the agent with the project file as the parameter, after he disables the calculator UI test, because UI tests cannot run from the command line. He shows that variables can be passed on the command line, which overrides their hard-coded values, or as TeamCity parameters of the environment variable type, which never override a local FinalBuilder variable, so he finds the command line safer.

Transcript

1,135 words

[00:03] (external link, opens in new tab) I'm going to show you how to run FinalBuilder from a CI from a CI server. In this case, my favorite CI these days is TeamCity. So, I'm going to show how I connect TeamCity and run FinalBuilder scripts from it. The first step to get a TeamCity project going is you need some source code to get it from. So, actually what I'm going to do is I'm going to initialize a Git repository in my demo folder. So if I just do a dir here, you can see that we have all our files including demo.

[00:36] (external link, opens in new tab) We don't care about FinalBuilder log and all that stuff, but for now we'll just include everything. Usually what you want to include is either an FBP or an FBZ7. So if I close the projects, usually what you'll see is an FBP7 or FBZ. FBZ is a FinalBuilder zip file. Usually that's the best form because it contains everything you want. But when you open a project, it opens up into a FBP file. So usually you just need the FBZ7

[01:09] (external link, opens in new tab) Or whatever the version of the of the script runner is. In this case, it's seven. So for us, what we're going to do now, we're just going to do a git init. Then we're going to do a git add everything. and git commit. And now I'm just going to say initial commit as my git comment. And if you don't know git, this is something that's I'm going to cover maybe in a different course, but for now, I'm assuming that you know a little bit of git.

[01:46] (external link, opens in new tab) I've just checked in all the source code and that's basically it. And the git the source control is directly in this directory here. So, what I'm going to do in TeamCity, I'm going to go to administration. I'm going to create a project. I'm going to call it FinalBuilder course demo project. I'm going to create it and then I can create what's called a VCS roots or I'm going to need to connect to some source control.

[02:19] (external link, opens in new tab) So in my source control repository URL is let's copy it from here. It's actually I have total commander here and again that probably be a different course but it's the folder mygit folder in my cfb demo. I'm just going to press control shift enter so I have everything loc located located here and then press the right arrow and control c to copy the path

[02:53] (external link, opens in new tab) And I'll just paste the path here. I don't need any admin or password. So I'm going just going to create that and I'm going to select git from the type and the fetch URL is going to be this one. Test connection works. Okay. Create. Now what I'm going to do, I'm going to go back to general settings.

[03:24] (external link, opens in new tab) Going to create a build configuration that will invoke my project file. So I'm just going to say invoke FinalBuilder build script. Now before I do that, it's important to mention that I disabled my run calc test because that's a UI test. You cannot run UI related stuff in command line. So this is disabled. I disable it by unchecking it here.

[03:56] (external link, opens in new tab) Going to close it. But this is what has to be in the source control. The FBZ file is in source control and it's usually I just keep it at the root. This way I don't have to know about the structure of the application and in different versions of it. It will always be at the root. Now in this build configuration, I just need to attach to my source control. I'm going to attach to it. And my first build step,

[04:27] (external link, opens in new tab) I'll have to configure one. I'm just going to create either a command line or PowerShell. Let's just do it with PowerShell for now. And the script type is going to be just source code. There's just directly I'm just going to say look where is the location of FBCMD on my machine on the machine that's on the agent that's going to run this. and local. Currently, my agent is local here on the machine and I have this software called everything which is a free software very easy to find. If I want to find fbcmd.exe,

[04:58] (external link, opens in new tab) It finds it very very quickly. It's here in this path. I'm going to actually right click on this from the everything software which again is it's open source. You can download it for free. copy full name to clipboard and just say invoke this and it will be invoked from the root of my source control which will be here. So I'm going to have demo one.fbz7. All I need to do is give the FinalBuilder command line demo one.

[05:33] (external link, opens in new tab) FBZ7 as the parameter. Going to say save. And now all I have left to do is I'm going to run this build configuration step. So I'm running it and it downloaded the repository. I can even click on this and look at the build log. You can see that it's already running step one of one.

[06:06] (external link, opens in new tab) And it's creating directories and all that stuff. And you can see the HTML that it downloaded from the Google website. And now it's basically exporting the log and it should already be done. So now we have success here. We can look at the build log. We can see everything. That's basically it. Now if I wanted to send any parameters there's a command line reference but basically you can go ahead and say in the build steps

[06:40] (external link, opens in new tab) That you will say that the slashp and then the project file name and slash v and the variable name would be some var name equals value one and then you would separate them like this. Some other varame equals value 2 etc. And those would basically override any any hard-coded values that you have.

[07:11] (external link, opens in new tab) But by default, you don't need to do this. And you can even pass things to the to the FinalBuilder command line via environment variables. How do you do that? Via parameters. I can even say add a new parameter in TeamCity which of of type environment variable. And here I can just give it the name like some var I use inside my

[07:42] (external link, opens in new tab) Script. And if in my script I listen to an environment variable with this name then I can set the value from it. However, note that if you try to send here an environment variable never overrides a local value that you have for a v for a variable inside FinalBuilder. So only use this for for environment variables and it's actually safer to just pass things through a command line.

[08:14] (external link, opens in new tab) So that's basically it for now for TeamCity.