如何在 Azure DevOps 中查看或获取服务连接 ID

Viv*_*Dev 1 azure azure-devops

有没有办法查看或获取我在 Azure DevOps 中创建的服务连接的服务连接 ID?

Azure DevOps 中的服务连接

我在创建的 yaml 管道中需要它们。例如,您在下面看到的 dockerRegistryServiceConnection 在 docker@02 任务中用于设置 containerRegistry(如果您看到下面的内容)。

variables:
- name: vmImageName
  value: ubuntu-latest

  # Container registry service connection established during pipeline creation
- name: dockerRegistryServiceConnection
  value: 'd072f8f7-fag1-asdf-467e-7fd5jfr5gjh6'  # This is not a true id
- name: imageRepository
  value: 'globoticket.services.discount'
- name: containerRegistry
  value: 'reacrtrialsregistry.azurecr.io'
- name: dockerfileFolderPath
  value: 'src/Services/GloboTicket.Services.Discount'
- name: tag
  value: '$(Build.BuildId)'


name: $(date:yyyyMMdd)$(rev:.r)

stages:

  - stage: Build
    jobs:
      - job: buildWebApp
        displayName: Build Release pipeline for Discount Service on Master branch
        pool:
          vmImage: $(vmImageName)

        steps:

        - checkout: self

        - task: Docker@2
          displayName: Build the image 
          inputs:
            command: build
            repository: $(imageRepository)
            dockerfile: $(dockerfileFolderPath)/Dockerfile
            buildContext: .
            tags: |
              $(tag)  
        
        - script: |
            sudo docker tag $(imageRepository):$(tag) $(containerRegistry)/$(imageRepository):$(tag)
          displayName: 'Tag container image before push'

        - task: Docker@2
          displayName: Push an tagged image to container registry
          inputs:
            command: push
            repository: $(imageRepository)
            dockerfile: $(dockerfileFolderPath)/Dockerfile
            buildContext: . 
            containerRegistry: $(dockerRegistryServiceConnection)
            tags: |
              $(tag)      

  - stage: DeployToDev
    displayName: Deploy to Dev Env
    jobs:
      - deployment:
      
        pool:
          vmImage: ubuntu-latest
        environment: Dev
        strategy: 
         runOnce:
           deploy:
             steps:
              - script: |
                    echo Any deploy stage starts here.
                displayName: 'Command Line Script to write out some messages'

                  
Run Code Online (Sandbox Code Playgroud)

dan*_*orn 6

根据文档containerRegistrydocker 任务的输入是服务连接的名称,而不是 id :

容器注册表(可选):Docker 注册表服务连接的名称

如果您仍然需要该 ID,可以单击下面列表中的服务连接Project Settings -> Service Connections,并从 url 中的 resourceId 参数中获取服务连接 ID:

在此输入图像描述