Task groups are really useful to share common actions with multiple build or release pipelines in Azure DevOps (VSTS). You can group multiple tasks ang create a task group forma build or release definition. then these task groups can be utilized in other build or release definitions in a given team project. Parameters in a task group help to pass values from build or release definition to the tasks in the task group. You can add a default value for these parameters or have to provide value from the build or release definition that is using the task group. Making a task group parameter optional is not straight forward and you need some do work around to get it working. Let’s look at how we can make a parameter optional for a task group in Azure DevOps pipelines.
$SqlDBServer and $SqlDBName are used as the local variables and $(SqlDatabaseServer) and $(SqlDatabaseName) are the input parameters. Note the single quotes which is important in the PowerShell if you are having PowerShell scripts as your task group steps. This will make two parameters available for the task group. You can provide a description for each parameter and a default value. However, default value is not utilized in this sample as we are tying to make the parameters optional.
If you try to use this task group in a build or a release definition you will see it demands for both parameters as required. In a side note, you can see the descriptions added to parameters are visible to the release or build definition.
How can we make one of the se parameters optional? For that you have no out of the box option available in Azure DevOps as of now. You have to export the task group and manually edit the json file to get it done. First export and save the json file.
Press Ctrl+k Ctrl+D in Visual Studio or Shift+Alt+F in Visual Studio Code to format the json file (for that matter to format any code file). After formatting you can see there is a section named inputs and each of the parameters available there. You can set the required false for any input parameter in the json file and save it.
Go to the build or release definition add new task group (you may have to do full refresh of the build/ release definition page with a Ctrl+F5 to make the changes in task groups to be effectively visible to you). You would be able to see not the optional parameter from task group is not demanding for a value. Not a neat solution but it works!!!