1

We are trying to create build definition by copy another build definition information using Azure Devops Rest API however getting the below error:

HttpError BadRequest - Value cannot be null. Parameter name: definition.Repository.Mappings.Mapping.ServerPath.

Here are the steps we are following

  1. Get the build information using API - This step is working fine
  2. Modify the name of the build definition
  3. Create the new build definition by passing the above build definitions request Body

Sample code

var buildDefinitionGet = client.GetBuildDefinitionsAsync("XXX.DevOps", "15");

var newBuildDefinition = buildDefinitionGet;
newBuildDefinition.name = "MVC2017-1";

var buildDefinition = await client               
   .CreateBuildDefinitionsAsync("XXX.DevOps", newBuildDefinition)
   .ConfigureAwait(false);

Here is the request body structure:

public class BuildDefinitionRequestBody
{
    public Process process { get; set; }
    public Repository repository { get; set; }
    public ProcessParameters processParameters { get; set; }
    public List<object> drafts { get; set; }
    public Queue queue { get; set; }
    public string name { get; set; }
    public string type { get; set; }
    public string queueStatus { get; set; }
}

We are using TFVC as source control.

Are we missing anything?

PaulG
  • 13,871
  • 9
  • 56
  • 78
  • What value are you passing for `definition.Repository.Mappings.Mapping.ServerPath`? – stuartd Feb 27 '19 at 11:36
  • Hi Stuart, In Repository we don't need to provide anything for Mappings section as per the link https://learn.microsoft.com/en-us/rest/api/azure/devops/build/definitions/create?view=azure-devops-rest-5.0 – tapas barma Feb 27 '19 at 12:23
  • also if we add the "$/XXX.ExtSource/MVC2017" in definition.Repository.Mappings.Mapping.ServerPath then also we are getting the same error – tapas barma Feb 27 '19 at 12:31

1 Answers1

0

In these scenarios, there are two type error,

definition.Repository.Mappings.Mapping.ServerPath” and “definition.Repository.Mappings.Mapping.LocalPath”.

Following situation in your path will cause above error.

definition.Repository.Mappings.Mapping.LocalPath:


  1. unc paths are not allowed
  2. local mappings are not allowed to be absolute paths or to navigate out of the s dir
  3. two mappings should not have the same local path
  4. Local Path number is 0 or mapping number is 0

definition.Repository.Mappings.Mapping.ServerPath:


  1. no invalid characters allowed
  2. no empty fields allowed for server path or type
  3. two mappings should not have the same server path

Since the screenshots doesn’t show the whole local path and the server path , please check the paths based on above rules on your side. And I suggest you copy the Server Path value from the corresponding project’s Code -> Files, on the top of the page, which could make sure the server paths are correct. For the local paths, I suggest you remove the one by one to make sure which one caused this issue.

Powershell equivalent code for cloning build.

$uri = 'https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}'

$result = Invoke-RestMethod -Method Get -Uri $uri -UseDefaultCredentials
$result.path = '\NewFolder\Location'
$result.name = "Testing"

$body = $result | ConvertTo-Json -Depth 7

Invoke-RestMethod -Method POST -uri 'https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=4.0' -UseDefaultCredentials -Body $body -ContentType 'application/json'

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • Hi Mohit, in below link from azure devops doc https://learn.microsoft.com/en-us/rest/api/azure/devops/build/Definitions/Create?view=azure-devops-rest-5.0#request-body if you check the repository section there is nothing about Mappings.Mapping.LocalPath and Mappings.Mapping.ServerPath where we need to put this values. If we add this in repository section and set the values then also it is giving same error. Could you please provide us some working sample code of Build definition creation using C#,Azure dev ops API for TfsVersionControl.We are not using git. – tapas barma Mar 05 '19 at 08:56
  • Try to give some value in the "neBuildDefinition.Path". and then try running your code.I am adding the equivalent power shell code for cloning Build definition in my answer. – Mohit Verma Mar 05 '19 at 09:37
  • Before posting this, i have tried in powershell and it worked for me, can you see if you are able to clone it using powershell code. – Mohit Verma Mar 05 '19 at 11:41
  • Also it seems that you have passed a solution path, try giving a relative path of folder name like "\newfolder\" and also pass a value in buildnumberformat too. You can refer below thread for the same. https://stackoverflow.com/questions/54524295/clone-vsts-build-definition-in-c-sharp – Mohit Verma Mar 05 '19 at 11:43
  • Hi Mohit, I have tried to run it in powershell However getting the below error The property 'path' cannot be found on this object. Verify that the property exists and can be set. At line:4 char:1 + $result.path = '\XXX.DevOps' also when i am running it from C# and Azure devops api and set the path = "\XXX.DevOps" and buildnumberformat ="$(date:yyyyMMdd)$(rev:.r)" getting the same expeption HttpError BadRequest - Value cannot be null. Parameter name: definition.Repository.Mappings.Mapping.ServerPath. – tapas barma Mar 06 '19 at 05:25