If you, like me, delete a Service Connection that was being used by a build definition and then try to edit that pipeline you may receive an error like "Cannot read properties of undefined (reading 'templatePath')".
Rather than deleting/recreating the whole pipeline and lose the history (if that's important), you can create a new service connection and update the connectedServiceId property of the build definition via the API.
First, get the current definition:
curl -u {username}:{pat} GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.0 | jq . > brokenbuild.json
