While configuring branch policies in Azure DevOps Server, I encountered a frustrating and somewhat cryptic error message: TFS.WebApi.Exception: TF402457: The settings for this policy are not correctly formatted. Error: File patterns are not supported for this policy type.
👾 What does this error mean?
This error occurs when attempting to apply file path filters (also known as file patterns) to a branch policy type that does not support them in Azure DevOps Server 2020 Update 1.2. It’s currently unclear whether this behavior is an intentional limitation or a bug that has been addressed in newer Azure DevOps Server releases. Since I wasn’t able to find a clear solution online, I thought it would be helpful to share a quick workaround based on my experience. If you encounter this behaviour with newer DevOps server releases as well please leave a comment.
🔍 Root Cause
The branch policy UI let you define a policy (Build Validation) and include file path filters. You can specify absolute paths (path must start either by / or a wildcard).
1 2 3 4 |
/WebApp/Models/Data.cs /WebApp/* */Models/Data.cs *.cs |
You can specify multiple paths using ; as a separator.
1 |
/WebApp/Models/Data.cs;/ClientApp/Models/Data.cs |
I was able to create a Build Validation policy and configure the path filter without any issues. However, as soon as I enabled an additional setting under Branch Policies, such as “Require a minimum number of reviewers”, I encountered the following error:
1 |
TFS.WebApi.Exception: TF402457: The settings for this policy are not correctly formatted. Error: File patterns are not supported for this policy type. |
Initially, I attempted to use Build Validation with file path filters on its own without enabling any reviewer requirements which left me puzzled, as the policy consistently failed to work without providing a clear reason. It wasn’t until I combined it with the reviewer policy that the system finally revealed the underlying issue.
âś… Workaround
When configuring the path filter through the Azure DevOps web portal, it appears that the paths may be improperly formatted, which causes issues on the backend and leads to errors like TF402457. If you need to work with Build Validation policies that include path filters, and want to avoid these problems, I recommend using the Azure DevOps CLI, which handles the configuration more reliably and allows for greater control over the policy setup.
Step 1 – Prepare Azure DevoOps CLI
1 2 3 |
az extension add --name azure-devops az devops configure --defaults organization=https://ado.contoso.com/Company project=IT az devops login --organization https://ado.contoso.com/Company |
Step 2 – Identify Repository ID
1 |
$REPO_ID=$(az repos show --repository <REPO-NAME> --query id --output tsv) |
Step 3 – Filter Branch Policies
1 2 3 4 5 6 7 8 9 10 11 12 |
$policies = az repos policy list --output json | ConvertFrom-Json $filteredPolicies = $policies | Where-Object { $_.settings.scope[0].repositoryId -eq $REPO_ID } $filteredPolicies | Format-Table policyType.displayName, id, settings.scope policyType.displayName id settings.scope ---------------------- -- -------------- 1889 1890 |
Step 4 – Identitfy Branch Policy
1 |
az repos policy show --policy-id 1890 |
Step 5 – Configure Path Filter
1 |
az repos policy build update --id 1890 --path-filter "/templates/win11_24h2/packer-win11-24h2_azure_standard.pkr.hcl" |
