© Chaminda Chandrasekara 2017

Chaminda Chandrasekara, Beginning Build and Release Management with TFS 2017 and VSTS, 10.1007/978-1-4842-2811-1_7

7. Task Groups, Folders, and Build/Release Definition History

Chaminda Chandrasekara

(1)Colombo, Sri Lanka

In this chapter, you will learn what a task group is and how to create and use them. Using the history and the comments provided by updaters of the definitions, you will be able to identify changes made to the build or the release definitions. You will also get to learn about grouping build or release definitions using folders and the use of tags.

What Is a Task Group?

A sequence of tasks can be encapsulated into a reusable task in the Task Catalog using a task group. This allows a task group to be added to a build or release definition like a normal task. You have the option to abstract the task information while extracting the required parameters from the encapsulated tasks. Task groups are scoped at the team-project level and are not visible to other team projects.

Lesson 7.01 – Create a Task Group

Let’s use a few PowerShell tasks to show what can be done with task groups. You can use any of the available tasks in a task group, but PowerShell tasks are used here to make the concept easy to understand.

  1. Create a new build definition with an empty template. Add three PowerShell tasks from the Task Catalog and add the following PowerShell as an inline script to all three tasks (see Figure 7-1):

    A434379_1_En_7_Fig1_HTML.jpg
    Figure 7-1. Build definition with three PowerShell tasks
    parame
    $CommonParam,
    $TaskParam1,
    $TaskParam2
    )
    write-host "Task 1 CommonParam Value:" $CommonParam
    write-host "Task 1 TaskParam1 Value:" $TaskParam1
    write-host "Task 1 TaskParam2 Value:" $TaskParam2
  2. For the first, second, and third tasks, provide the arguments as specified here (see Figure 7-2):

    A434379_1_En_7_Fig2_HTML.jpg
    Figure 7-2. PowerShell task two

    First Task Arguments:

    -CommonParam $(CommonParam) -TaskParam1 $(Task1Param1) -TaskParam2 "Task1FixedValueforParam2"

    Second Task Arguments:

    -CommonParam $(CommonParam) -TaskParam1 "Task2FixedValueforParam1" -TaskParam2 "Task2FixedValueforParam2"

    Third Task Arguments (see Figure 7-3 ):

    A434379_1_En_7_Fig3_HTML.jpg
    Figure 7-3. PowerShell task three
    -CommonParam $(CommonParam) -TaskParam1 "Task3FixedValueforParam1" -TaskParam2 $(Task3Param2)
  3. Select all three PowerShell tasks and right click; select “Create task group” from the dropdown. See Figure 7-4.

    A434379_1_En_7_Fig4_HTML.jpg
    Figure 7-4. Grouping tasks
  4. In the popup window , define the default values and descriptions (not mandatory) for parameters. Provide a description and select Utility for the Task Catalog category. You can select Build, Deploy, Package, Utility, or Test as the category of the task group so that it appears in the appropriate tab of the Task Catalog. See Figure 7-5.

    A434379_1_En_7_Fig5_HTML.jpg
    Figure 7-5. Creating a task group
  5. This will instantly convert the tasks in the build definition to the task group. You can see the default values specified appear, and the parameters defined are ready for values to be entered. The description entered can be viewed when the mouse hovers over the information icon. See Figure 7-6.

    A434379_1_En_7_Fig6_HTML.jpg
    Figure 7-6. Build definition tasks converted to task group
  6. Provide values for the parameters CommonParam and Task1Param1. Make sure to enable the task execution by selecting “Enabled” in the Control Options section. See Figure 7-7.

    A434379_1_En_7_Fig7_HTML.jpg
    Figure 7-7. Using task group in build definition
  7. Save the build definition, giving it the name “TskGroupTest,” and queue a new build. You will see all of the values (values specified in encapsulated tasks and values provided as parameters in the task group) appear in the log. This way you can expose required parameters from the task group while hiding any private values inside the task group you create. See Figure 7-8.

    A434379_1_En_7_Fig8_HTML.jpg
    Figure 7-8. Values in task group and parameters provided to task group shown in log
  8. Change a default value, and you will see the effects when a new build is queued. See Figure 7-9.

    A434379_1_En_7_Fig9_HTML.jpg
    Figure 7-9. Change Task3Param2
  9. When saving the build definition , make sure to provide a comment. This will be useful when the history of the build definition is inspected. See Figure 7-10.

    A434379_1_En_7_Fig10_HTML.jpg
    Figure 7-10. Saving build definition
  10. Queue a new build, and it shows the changed value in PowerShell task three. See Figure 7-11.

    A434379_1_En_7_Fig11_HTML.jpg
    Figure 7-11. Task3Param2 shown when build is running

In this lesson, you learned how to easily create a task group using existing tasks in a build definition. In the same way, you can create a task group using a set of tasks in a release definition.

Lesson 7.02 – Use a Task Group

You can use a task group you created in a different build or release definition within the team project.

  1. Open an existing build definition or create another build definition in the same team project you created the task group in during the previous lesson. Then, open up Task Catalog and go to the Utility tab to find the task group. See Figure 7-12.

    A434379_1_En_7_Fig12_HTML.jpg
    Figure 7-12. Task group available as a task in Task Catalog in a build definition
  2. The same thing can be done with a release definition. See Figure 7-13.

    A434379_1_En_7_Fig13_HTML.jpg
    Figure 7-13. Task group available as a task in Task Catalog in a release definition

You can create your own task groups using the existing tasks in your build or release definition and reuse them in other build/release definitions you are creating in the same team project. This allows you to avoid duplication of the same set of tasks in different build/release definitions and increases the maintainability of the definitions.

Lesson 7.03 – Manage Task Groups

To manage existing task groups , you can use the Task Groups tab.

  1. In the Build & Release menu, click on Task Groups. See Figure 7-14.

    A434379_1_En_7_Fig14_HTML.jpg
    Figure 7-14. Task groups
  2. You can edit the parameters’ default values and other information, such as where the task group’s tasks appear in the Task Catalog. See Figure 7-15.

    A434379_1_En_7_Fig15_HTML.jpg
    Figure 7-15. Editing a task group
  3. Click on Tasks to view the steps in the task group. You can edit the individual tasks in a task group and add new tasks from the Task Catalog to the task group by clicking on Add tasks. See Figure 7-16.

    A434379_1_En_7_Fig16_HTML.jpg
    Figure 7-16. Editing task group tasks
  4. Add another PowerShell task and use the same inline script. Pass arguments as given below (see Figure 7-17):

    A434379_1_En_7_Fig17_HTML.jpg
    Figure 7-17. Adding a new task to task group
    -CommonParam $(CommonParam) -TaskParam1 "Task3FixedValueforParam1" -TaskParam2 $(Task4Param2)
  5. You can see a new parameter getting added to the task group since you specified $(Task4Param2) as a parameter for the fourth task, which was added in the previous step. Do not provide a default value for the new parameter. See Figure 7-18.

    A434379_1_En_7_Fig18_HTML.jpg
    Figure 7-18. New parameter in task group
  6. Save the task group and open the build definition that is using the task group so the definition can be edited. The build definition now has another mandatory parameter for the task (task group task from catalog). See Figure 7-19.

    A434379_1_En_7_Fig19_HTML.jpg
    Figure 7-19. New parameter in task group is required in the build definition that is using the task group
  7. Provide the value Task4Param2ValueviaBuild in the build definition, save, and queue a build to verify. See Figure 7-20.

    A434379_1_En_7_Fig20_HTML.jpg
    Figure 7-20. New parameter value shown in build log

You learned how to manage an existing task group in this lesson. Do further experiments by modifying the task group in order to understand more about them.

Lesson 7.04 – Organize Folders to Group Builds

When you have multiple build definitions in a team project, you might find at times it is not easy to locate a given build definition. To group or categorize your build definitions, you can use folders, as shown in the following steps.

  1. In the Builds tab, go to All Definitions and click Manage Folders. See Figure 7-21.

    A434379_1_En_7_Fig21_HTML.jpg
    Figure 7-21. Manage folders for grouping build definitions
  2. Click on Create new folder, provide a name, and click OK. See Figure 7-22.

    A434379_1_En_7_Fig22_HTML.jpg
    Figure 7-22. Creating new folder
  3. Then, click on the menu link for a build and choose Move definition. See Figure 7-23.

    A434379_1_En_7_Fig23_HTML.jpg
    Figure 7-23. Move build definition to a folder
  4. Select the folder and click OK, as shown in Figure 7-24.

    A434379_1_En_7_Fig24_HTML.jpg
    Figure 7-24. Selecting a folder for build definition
  5. This way, you can group your build definitions into folders to organize them properly. See Figure 7-25.

    A434379_1_En_7_Fig25_HTML.jpg
    Figure 7-25. Build definition moved to folder

You can use folders to group your build definitions in order to keep them organized and categorized in your team project.

Lesson 7.05 – Track Build/Release Definition History

Build and release definitions are stored as json files in TFS. You can view the history of updates and compare changes to get an idea of what has been changed in a definition. You can roll back to a previous version of the build definition. But, for release definitions, rollback is not available.

  1. Go to the build definition named TskGroupTest, created in Lesson 7.01, and edit it. Go to the History tab. You can see the comments provided while saving and see the change history. See Figure 7-26.

    A434379_1_En_7_Fig26_HTML.jpg
    Figure 7-26. Build definition history
  2. You can view the differences by selecting two versions and clicking on Diff, as shown in Figure 7-27.

    A434379_1_En_7_Fig27_HTML.jpg
    Figure 7-27. Build definition version comparison
  3. In the build definition history, you can select a version and click on Rollback to go back to that version of the build. See Figure 7-28.

    A434379_1_En_7_Fig28_HTML.jpg
    Figure 7-28. Rollback build definition
  4. In the new build editor layout (explained in Chapter 1), you can see the rollback option and comparison of definitions via a menu link. Rollback is available as Revert Definition, and Diff is available as Compare difference. See Figure 7-29.

    A434379_1_En_7_Fig29_HTML.jpg
    Figure 7-29. Rollback and Diff in new build definition layout

In this lesson, you learned how to use the build/release definition History tab.

Summary

In this chapter, you learned about task groups. These help you group a common set of tasks into a single unit of functionality, which could be shared between multiple build definitions or release definitions while parameterizing as required. This provides higher maintainability in build/release definitions.

Organizing builds using folders allows you to maintain a proper structure and to categorize your builds. This is useful if you are using a large team project with multiple teams, or applications with multiple builds.

The build and release history allows you to track changes made to a definition. Rollback of build definitions lets you go back to the previous versions easily if you made any mistakes in an update. This would be a really nice feature to have for release definitions as well, and will eventually be available in the future.

In the next chapter, you will learn how to build source code in external repositories using Team Services build.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.219.166