0
votes

I want to automate service connection creation for a given azure devops project as a part of my deploy script. I looked into Terraform but it does not support it yet. ARM template also does not have anything for service connection.

https://docs.microsoft.com/en-us/azure/devops/cli/service_endpoint?view=azure-devops

This link has some notes on how to do it. I have captured the post request body as the link says, and stored it in config.json file

I am running the following command to create a service principle.

az devops service-endpoint create --service-endpoint-configuration config.json --organization "https://dev.azure.com/ojaskale" --project "Test Project"

This does create a service connection but this one does not work. If I create a service principle from console It works as expected.

I am getting following error message.

The pipeline is not valid. Job Build: Step Docker input containerRegistry references service connection acrserviceconnectiontest which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz.

I can see acrserviceconnectiontest in my build.yml.

Azure guidelines say I need to copy the post requests body and fill in the required details. post body does not have servicePrincipalId by default. I did some research and figured out I need to create one and assign roles to it which I am doing. There are two scripts given here, I am following those.

https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-service-principal

Once I create service principle I get following output.

Service principal ID: xxxxxxxxxxxxxxxxxxxxxxxxxx
Service principal password: xxxxxxxxxxxxxxxxxxxxxxxxxx

I have tried both of them in place of servicePrincipalId but none of them seem to work.

service principle id of the working service connection is different than one I create using cli.

I think I am very close to getting it working, as I can see service connection getting created but it does not work. Can someone point me what I am missing or doing wrong? Thanks.

1

1 Answers

0
votes

for the service connection which you are referencing you should use whatever is under the name property in your config.json