Friday, 12 August 2011

Automated builds using C/C++ and Rational Team Concert

In the previous two posts (Part 1 , Part 2), I went through the process of setting up the basics to get started with C/C++ in Rational Team Concert. We were building and running the code from RTC menus and while this is fine for a one person code hobbyist it isn't really enough if we want to create quality code in a team production environment.  For that, we need to set up some automated tests and builds and in this post I will go through the steps on how to set up an automated C/C++ build in Rational Team Concert. We will be building the OSLC code sample that we imported in Part 2 for this exercise.

What you will need:

1. Rational Team Concert Client 3.0.1
2. Jazz Team Server with Change and Configuration Management (CLM 3.0.1)
3. Build System Toolkit 3.0.1
4. Ensure you have mingw32-make (see Part 1) is in your PATH and installed:
mingw-get install mingw32-make

I am going to assume that the Jazz Team Server 3.0.1 is installed with the change and configuration management application and that you have created a new project area with the out-of-the-box Scrum process called "CDT". If you do not know how to connect to a repository or create a project area I will refer you to the CLM 3.0.1 information center. Information on how to get set up, plus more, can be found there. If all went well, then your project area in the Team Artifacts View of the Work Item perspective should look like this:
IMPORTANT: Make sure you are assigned to the project as "Scrum Master"! Being project administrator is not enough.

We have a default stream and a default component and to keep things simple we will be using those for this exercise. Go the C/C++ perspective in RTC and deliver the OSLC Consumer project into the default stream and component.

Here's how to do it:

1. Right Click on the OSLC Consumer->Team->Share Project->Jazz Source Control

2. You will see that a workspace has already been created for you that is following the default stream. Select the CDT Stream Workspace's Default Component and then "Finish"

3. Now that we've added the project to the workspace we can simply deliver it to the stream by going into the Pending Changes View right clicking on the CDT Stream Workspace and selecting "Deliver"
NOTE: I will not associate a work item to the delivery at this point but we will do this later with another delivery.

4. Now our code is in the default stream which we will now set up for an automated build.

5. First thing we should do is set up a separate workspace for the build engine.  We could use our default workspace for this but as we are working on the code it would not be buildable and we also don't want the build engine to load over our work.
Go to the Team Artifacts View of in the Work Item perspective. Right click on "My Repository Workspaces". Select the default stream:
Click "Next" and call the new build workspace: "Build CDT Workspace". Click Next twice to get to the page asking for Read Access Permission. Select "Public".
NOTE: Usually you would want to make this private to the build engine but again for simplicity we will make it public.

Click "Next" again and ensure that the Default Component is selected and "Load repository workspace after creation" is unchecked.
Click "Finish".

6. Next is to create a build engine and a build definition. To create a build engine we will simply right click on the build engines section of our project area:
Click next and ensure we are creating a new build engine called "CDT engine" and that it is the "Jazz Build Engine" type. Click "Finish" and then click the "Save" button in the top right corner of the new build engine.

7. Now that we have an engine we need to define a build. Right click on "Builds" this time.
Select "New Build Definition...". Click "Next" to create a new build using the "Command Line - Jazz Build Engine" template. Leave the ID as "CDT build". Click Next and select "Jazz Source Control" in the Pre-Build page. Everything else will be default for now so click "Finish".

8. In the new build definition type "mingw32-make clean all" in the "Command" field of the "Command Line" tab and also set the working directory to be the location of the Makefile (we will add it to the project):

9. In the "Jazz Source Control" tab set the Build workspace to the one we just created for this build: "Build CDT Workspace" and select a Load directory in "Load Options" (In my case it is C:\build\CDT). Also Select "Delete directory before loading".
NOTE: A dialog will popup regarding the build owner. Press Ok.

 
Add the "CDT engine" in the "Supporting Build Engines" section of the "Overview" tab:

Click "Save" in the top right corner.

10. Now that we have defined a build engine and a build we need to set up the Jazz Build Engine to perform the build as we chose to use it for builds. Extract the Build System Toolkit 3.0.1 in a memorable location. (Mine is directly in the C: drive: C:\jazz).

11. Add the directory with the jbe comand line into the PATH environmental variable. (C:\jazz\buildsystem\buildengine\eclipse in my case).

12. Open up a command prompt and start the build engine:
jbe -repository https://<server name>:<server port>/ccm -userId <usermame> -pass <password> -engineId "CDT engine" -sleeptime 1

Replace the server name, port username and password with those that you use to connect to the CCM application on the Jazz server. If everything went well you should only see:

14. We are using a Makefile tool for our build so we need a Makefile in our project. We could get RTC to generate the build file for us but as we need to use it for our build engine we should keep it simple. For your convienience I have created one here.
Save the Makefile into the root of the "OSLC Consumer" project directory in your RTC workspace.  In RTC, right click the "OSLC Consumer" project in the project explorer and select "Refresh"

15. In order to test the make file we need to set the project builder to using mingw32-make. To do this we go to the project properties by right clicking on "OSLC Consumer". Go to C/C++ Build->Tool Chain Editor and select "Gnu Make Builder" For both the Release and Debug configuration:
Then select the "C/C++ Build" section and select "All Configurations" in the Configuration pull down. Use an External builder and make sure the Build command is mingw32-make and that the "Generate Makefiles automatically" option is off:

16. Now we are using the Makefile instead of the internal builder so lets try to build it by right clicking on the project and selecting "Build Project". It should build without errors.

17. Now lets check in the Makefile in the SCM. Right click on the Makefile and select Team->Check In and Deliver. A dialog will pop up and you can put a comment. Click "Next".

18. We are now going to create a work item so click the "Create Work Item" option. In the next screen you can fill in a task as in the screenshot:

Click "Finish". If it asks you if you want to check in changes then click "Yes".

17. That should be it! Lets request an automated build. Go back to RTC to the work item perspective and request a build by right clicking on the build and selecting "Request Build...".
If all goes well you should see a successful build in the builds view (you may need to refresh it a few times):
 
You can double click on the build result and inspect the build result record. You should see:
- The code changes in the build
- The build logs
- The workspace that was built
- 1 work item in the build (the one we created earlier.)
- A snapshot

This is quite a long blog so I will cut it short here.  In any case you can go into the build definition and schedule the build to run whenever you want.

Next time I will continue enhancing the feedback from the Makefile build.

No comments:

Post a Comment