Search code examples
azureazure-devopstfsazure-devops-rest-api

Create pipleine in Azure devops by rest API failed - Value cannot be null. Parameter name: repositoryName


I am tring to create Azure devops (tfs) Pipeline by rets API as described here: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-6.0

Request url: https://tfs.xxx/tfs/Projects/xxx/_apis/pipelines?api-version=6.0-preview Request body:

{   
    "folder": null,   
    "name": "pipeline-made-by-api",   
    "configuration": {     
        "type": "yaml",     
        "path": "build.yaml",     
        "repository": {       
            "id": "xxx",       
            "name": "xxx-repo",       
            "type": "azureReposGit"     
        }   
    } 
}

I got error 400 with response:

{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: repositoryName","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}

I don't see any parameter called repositoryName in the documentation.

What am i missing?

Thanks!

EDITED:

I tried by shell script too:

This is the script (copied from @wade zhou - MSFT answer) enter image description here

This is the results: enter image description here


Solution

  • The shell script sample:

    PAT="PAT"
    ORG_URL="http://vm0/DefaultCollection"
    PROJECT="Project2"
    PIPELINE_NAME="test2"
    YAML_PATH="build.yml"
    repositoryId="3axx-1xx8-4xxb-8xx6-800xx4594e"
    repositoryName="Project2"
    
    
    curl -u ":$PAT" -X POST -H "Content-Type: application/json" \
      -d '{
        "configuration": {
          
          "type": "yaml",
          "path": "'"$YAML_PATH"'",
          "repository": {
            "id": "'"$repositoryId"'",
            "name":"'"$repositoryName"'",
            "type": "azureReposGit"
          }
        },
        "name": "'"$PIPELINE_NAME"'",
        "folder": "testfolder"
    
      }' \
      "$ORG_URL/$PROJECT/_apis/pipelines?api-version=6.0-preview"
    

    enter image description here

    Edit:

    For the error Value cannot be null.\r\nParameter name: repositoryName", as per your ADO version 2020(Dev18.M170.7), there is a bug reported before in community link, it's fixed in 2020.1. Please install server patch to upgrade, then try again.