I've devised a workaround that relies on using Azure DevOps for the CICD pipeline. If you don't already have a DevOps pipeline I suggest reading this article first.
I added a folder called Connectors to my Repo and copied the connectionparameters.json file for the custom connector I'd created. Inside this json I add the missing clientSecret e.g
"oAuthSettings": {
"identityProvider": "aad",
"clientId": "@environmentVariables(\"APIClientID\")",
"clientSecret": "@environmentVariables(\"APIClientSecret\")",
then within my pipeline I add a CopyFiles@2 task like this:
- task: CopyFiles@2
displayName: 'Copy Connector Settings Files to: $(Build.SourcesDirectory)/$(SolutionName)/Connectors'
inputs:
SourceFolder: Connectors
Contents: '**'
TargetFolder: '$(Build.SourcesDirectory)/$(SolutionName)/Connectors'
OverWrite: true
So essentially I'm overwriting the CustomConnectorName_connectionparameters.json file with a file stored in the source control. I only have one custom connector but could apply this for any custom connectors. Hope this helps somebody.