FredE
FredE

Reputation: 71

Add steps to a build definition in AzureDevOps 2019

I'm trying to create ADOS build definitions programmatically. I found a similar question with an answer here: How to create Build Definitions through VSTS REST API

In the answer example, the steps property is empty. I included some steps (taken from a JSON gotten from another build definition using the same API). The result is that the created build definitions has no steps.

I dug into the .NET API browser, and found that there is a BuildProcess classs with a Process property which should take a DesignerProcess for TFVC pipelines (since YAML is only suported for Git repos), DesignerProcess has a Phase property which is readonly, that maybe the reason why it's not creating my steps

However I still need to find out a way to create a builds steps programmatically

Upvotes: 0

Views: 442

Answers (1)

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5182

However I still need to find out a way to create a builds steps programmatically.

If you don't know what to add to the step property, you can grab request body in developer console window when saving a Classic UI Pipeline.

Here are the detailed steps:

  1. Create a Classic UI with steps you want in ADOS. (Don't save it in this step)

  2. If you are using edge, press F12 to open developer console window. Then choose 'NetWork'.

  3. Click Save and you will find a record called 'definitions'.

  4. Click it and the request body is at the bottom of the page. You will find steps-related information in Process and processParameters properties.

If you are using a different browser, there might be some slight differences in step 2, 3 and 4.

Then you can edit and add the script in your REST API request body.

Here is a simple example of request body that includes a Command Line task.

"process": {
    "phases": [
        {
            "condition": "succeeded()",
            "dependencies": [],
            "jobAuthorizationScope": 1,
            "jobCancelTimeoutInMinutes": 0,
            "jobTimeoutInMinutes": 0,
            "name": "Agent job 1",
            "refName": "Job_1",
            "steps": [
                {
                    "displayName": "Command Line Script",
                    "refName": null,
                    "enabled": true,
                    "continueOnError": false,
                    "timeoutInMinutes": 0,
                    "alwaysRun": false,
                    "condition": "succeeded()",
                    "inputs": {
                        "script": "echo Hello world\n",
                        "workingDirectory": "",
                        "failOnStderr": "false"
                    },
                    "overrideInputs": {},
                    "environment": {},
                    "task": {
                        "id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
                        "definitionType": "task",
                        "versionSpec": "2.*"
                    }
                }
            ],
            "target": {
                "type": 1,
                "demands": [],
                "executionOptions": {
                    "type": 0
                }
            },
            "variables": {}
        }
    ],
    "type": 1,
    "target": {
        "agentSpecification": {
            "metadataDocument": "https://mmsprodea1.vstsmms.visualstudio.com/_apis/mms/images/VS2017/metadata",
            "identifier": "vs2017-win2016",
            "url": "https://mmsprodea1.vstsmms.visualstudio.com/_apis/mms/images/VS2017"
        }
    },
    "resources": {}
}

What's more, creating YAML pipelines by REST API is not supported currently. Click this question for detailed information.

Upvotes: 1

Related Questions