简体   繁体   中英

How to view or get the service connection id in Azure DevOps

Is there a way to view or get the service connection ids for the service connections that I create in Azure DevOps?

Azure DevOps 中的服务连接

I need them in yaml pipelines that I create. For example, dockerRegistryServiceConnection that you see in the following is used in the docker@02 task for setting containerRegistry, if you see below.

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'

                  

The input for the containerRegistry input for the docker task is the name of the service connection, not the id, according to docs :

Container registry (Optional): Name of the Docker registry service connection

If you still need the ID, you can click the service connection in the list under Project Settings -> Service Connections and fetch the service connection ID from the resourceId parameter in the url:

在此处输入图像描述

All Azure Tasks I know are using the service connection name , not the Id. The same is true for the Docker@2 Task:

在此处输入图像描述

Source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM