Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPipelinesApi.createPipeline() cannot create a YAML pipeline, incompatible with the schema of the Azure DevOps REST API #592

Open
ovalice opened this issue Mar 26, 2024 · 1 comment

Comments

@ovalice
Copy link

ovalice commented Mar 26, 2024

Environment

Node version: v18.19.0
Npm version: 10.2.3
OS and version: Linux 5.10.102.1-microsoft-standard-WSL2 - linux/x64
azure-devops-node-api version: 13.0.0

Issue Description

The new IPipelinesApi.createPipeline() that has been published under version 13 seems to have several incompatibilities with the Azure DevOps REST API for creating a YAML pipeline. The function accepts an incomplete list of values that the REST API requires. The expected values seem to be copied directly from what is documented in the REST API documentation, but that documentation is NOT correct.

IPipelinesApi.createPipeline() and the the documentation at https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-7.1 should be corrected to reflect the parameters that the REST API actually expects.

Expected behaviour

I've been looking at blogs from other parties (such as this one) to see what the Azure DevOps REST API expects for creating a new pipeline. Thanks to those, I made the following fetch request:

await fetch(`${orgUrl}/${project}/_apis/pipelines?api-version=7.1-preview.1`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': `Bearer ${token}`,
      'X-TFS-FedAuthRedirect': 'Suppress',
    },
    body: JSON.stringify({
      name,
      folder,
      configuration: {
        type: 'yaml',
        path: pathToYamlFile,
        repository: {
          id: repositoryId,
          name: repositoryName,
          type: 'azureReposGit',
        },
      },
    }),
  });

And this works as expected, where it creates a pipeline within Azure DevOps (assuming the properties in the sample fetch exist).

Actual behaviour

To create a new YAML pipeline, the type definition of IPipelinesApi.createPipeline() requires me to call the function as follows:

  const project = 'MyProject';
  const pipelinesApi = await azureDevOps.getPipelinesApi();

  const pipeline = await pipelinesApi.createPipeline({
    name: 'test',
    folder: '/',
    configuration: {
      type: ConfigurationType.Yaml, // An enum which is equal to literal value 1
    }
  }, project);

This results in the following error thrown:

Error: This API does not support creating pipelines of configuration type Yaml.
  at RestClient.<anonymous> (node_modules/typed-rest-client/RestClient.js:202:31)    
  at Generator.next (<anonymous>)
  at fulfilled (node_modules/typed-rest-client/RestClient.js:6:58)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This seems to make sense. When I reproduce the request that is made, which would look like the following:

organization='<org>'
project='<project>'
token='<bearer_token>'

curl --location --request POST "https://dev.azure.com/$organization/$project/_apis/pipelines?api-version=7.1-preview.1" \
--header "Authorization: Bearer $token" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-TFS-FedAuthRedirect: Suppress' \
--data-raw '{
    "name": "pipelinename",
    "folder": "/"
    "configuration": {
        "type": 1
    }
}'

I get the same error in the body of the REST API.

This happens because the value 1 is not valid for configuration.type. It should be the string literal yaml in case you want to make a YAML pipeline. I expect more errors to occur when that single issue is fixed, since there is no way to specify a repository name or path to the yaml file.

@vmapetr
Copy link
Contributor

vmapetr commented Apr 1, 2024

Hi @ovalice, thanks for reporting!
We are working on more prioritized issues at the moment, but will get back to this one soon.

@vmapetr vmapetr added the bug label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants