Skip to content

Instantly share code, notes, and snippets.

@SydoxX
Last active October 22, 2025 17:22
Show Gist options
  • Select an option

  • Save SydoxX/9acb5003f8a7d811959624677df04938 to your computer and use it in GitHub Desktop.

Select an option

Save SydoxX/9acb5003f8a7d811959624677df04938 to your computer and use it in GitHub Desktop.

ContainerRegistryParser

This step grabs the registry URL from a docker service connection and sets the variable ContainerRegistryParser.Url.

Example of use in pipeline:

- template: templates/steps/ContainerRegistryParser.yml@pipelineAccessories
  parameters:
    containerRegistry: "dockerhub"
- pwsh: echo $(ContainerRegistryParser.Url) # Outputs i.e. docker.io
parameters:
containerRegistry: ''
steps:
- pwsh: Set-Content -Path "$(Agent.TempDirectory)/Dockerfile-$(Build.BuildId)" -Value "FROM scratch"
displayName: Create temporary Dockerfile
- task: Docker@2
displayName: Build temporary container
inputs:
command: build
containerRegistry: ${{parameters.containerRegistry}}
Dockerfile: $(Agent.TempDirectory)/Dockerfile-$(Build.BuildId)
repository: donotnamearepositorylikethis-$(Build.BuildId)
- pwsh: |
$imageName = "donotnamearepositorylikethis-$(Build.BuildId)"
$registry = docker images --format "{{.Repository}}" | Where-Object { $_ -match "$imageName$" } | FOrEach-Object { if ($_ -match '^([^/]+\.[^/]+)/') { $matches[1] } }
Write-Host "##vso[task.setvariable variable=Url;isOutput=true]$registry"
Write-Host "Parsed $registry."
displayName: Parse URL
name: ContainerRegistryParser
- pwsh: docker rmi $(ContainerRegistryParser.Url)/donotnamearepositorylikethis-$(Build.BuildId)
displayName: Remove temporary container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment