Forum Discussion

Harmanvir's avatar
Harmanvir
Copper Contributor
Jan 04, 2024

Printing azure repo name in the azure pipeline yaml file

I want to get the name of the azure repo in the azure pipeline while being executed. I am using templetes in the pipeline code and my repo always changes. I tried using Build.Repository.Name but it did not work. Is there any other way to get the name of repo?

1 Reply

  • You may try the following as an alternative:

     

    1. Use System.PullRequest.SourceRepositoryUri (if using PRs)

    If your pipeline is triggered by a pull request, you can extract the repository name from the source repository URI:

    - script: echo $(System.PullRequest.SourceRepositoryUri)
      displayName: "Print Repo Name from PR Source"

     

    1. Extract from Build.Repository.Uri

    Try using the repository URI and parse out the repo name from it:

    - script: echo $(Build.Repository.Uri)
      displayName: "Print Repo URI"

     

    1. Use Build.SourceBranchName (if working with branches)

    If your repo structure follows a naming convention tied to branches, you might be able to extract it dynamically:

    - script: echo $(Build.SourceBranchName)
      displayName: "Print Source Branch Name"

     

Resources