If you've used Azure Pipelines long enough, you may encounter issues with project build pipelines. Among the most catastrophic ones I encountered has to do with a broken connection between the build pipeline and the project's associated git repository.
Clicking on 'Edit' for the pipeline within Pipelines > Builds presents the Pipeline editor but with the error:
An error occurred while fetching the pipeline. Could not find the service connection associated with this pipeline.
Besides, all pipeline settings are grayed out, providing no easy way to fix the pipeline:
The glitch is indeed puzzling and will likely lead most users to resort to setting up a new build pipeline for the project, and having to archive the broken pipeline together with its past build jobs. I suspect mine was due to expired OAuth GitHub tokens which broke all my existing build pipelines.
So how can we salvage a pipeline to get it functioning like how it's supposed to?
Click on the back arrow button to return to the build pipeline's summary page.
Go the the workflow settings page.
a. Identify the username, project name, and definition id in the browser URL.
b. Substitute the bold texts in the following link with your respective values. For instance, username foo, project name bar-project, definition id 14:
c. Go straight to the link in your browser, which will take you to the YAML settings of the build pipeline to repair it.
Click on 'Get sources'.
Click on '…' to the right of 'Repository', and select the repository to connect to. In cases where the git repository url is still intact, no errors will appear. Simply re-select the same repository again to be sure.
Click on the drop-down arrow beside 'Save & queue' and select 'Save'. Provide an optional save message such as 'Fix broken pipeline'.
Check if the pipeline is functioning
Now click on 'Summary' to return to the pipeline's builds page. Then access the Pipeline Editor via 'Edit'. You should see the git repository's azure-pipelines YAML file appearing in the editor without error:
Congratulations, the build pipeline should be functioning again with its build history intact.
Perform the same steps for each broken pipeline you wish to recover.
That's all for now. Feel free to leave a comment if you're still facing this issue or similar ones on Azure Pipelines so we can all find solutions to them and be on the lookout.