bashazure-devopsazure-pipelinesazure-devops-rest-apiazure-devops-pipelines

Azure Devops Get a repositoryId by using repository name


I am writing a BASH script, where its creating an azure repo and then pushing code. post this step it will go-ahead and create an azure pipeline via azure-pipeline.yaml file present in the Azure repo.

At this step we need to pass the repository ID in-order to create the pipeline, but issue here is I can't keep it as a user input as it will be getting created within script itself, now I am struck with this.

Is there any way that we can get the repo id from the newly created repo directly within the script?

https://dev.azure.com/{{organization}}/{{project}}/_apis/pipelines?api-version=6.0-preview.1
{
    "folder": "Folder-Name",
    "name": "Pipeline-Name",
    "configuration": {
        "type": "yaml",
        "path": "azure-pipelines.yml",
        "repository": {
            "id": "Repo-ID",
            "name": "Repo-Name",
            "type": "azureReposGit"
        }
    }
}

Solution

  • This can be done by taking the output to another file as a variable (As suggested by @Shayki Abramczyk), then with the help of below command we can call the ID variable in the script file

    $ jq -r '.id' Repooutput.txt
    dad04f6d-4e06-4420-b0bc-cb2dcfee2dcf