1
votes

I'm trying to create a release definition by using Azure DevOps REST API. I've created a json file which has configuration details for the request. I'm getting the below error, while creating the release definition.

{
    "$id": "1",
    "innerException": null,
    "message": "Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid. Add valid tasks and try again.",
    "typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data",
    "typeKey": "InvalidRequestException",
    "errorCode": 0,
    "eventId": 3000 
}

I'm using the below request body to create a new release definition in Azure cloud.

{ "name": "myreleasedefn1", "artifacts": [{ "type": "DockerHub", "alias": "_dockerusername_mydockerimage", "definitionReference": { "connection": { "id": "dd986f4a-123k-45d5-b8e6-fc4fds23rce", "name": "dockerservice" }, "defaultVersionType": { "id": "selectDuringReleaseCreationType", "name": "Specify at the time of release creation" }, "definition": { "id": "dockerusername/mydockerimage", "name": "dockerusername/mydockerimage" }, "namespaces": { "id": "dockerusername", "name": "dockerusername" } }, "isPrimary": true, "isRetained": false }], "releaseNameFormat": "Release-$(rev:r)", "environments": [{ "name": "development", "rank": 1, "retentionPolicy": { "daysToKeep": 30, "releasesToKeep": 3, "retainBuild": true }, "preDeployApprovals": { "approvals": [ { "rank": 1, "isAutomated": true, "isNotificationOn": false, "id": 10 } ], "approvalOptions": { "requiredApproverCount": null, "releaseCreatorCanBeApprover": false, "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false, "enforceIdentityRevalidation": false, "timeoutInMinutes": 0, "executionOrder": "beforeGates" } }, "postDeployApprovals": { "approvals": [ { "rank": 1, "isAutomated": true, "isNotificationOn": false, "id": 12 } ], "approvalOptions": { "requiredApproverCount": null, "releaseCreatorCanBeApprover": false, "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false, "enforceIdentityRevalidation": false, "timeoutInMinutes": 0, "executionOrder": "afterSuccessfulGates" } }, "deployPhases": [{ "deploymentInput": { "parallelExecution": { "parallelExecutionType": "none" }, "agentSpecification": { "identifier": "ubuntu-16.04" }, "skipArtifactsDownload": false, "artifactsDownloadInput": { "downloadInputs": [] }, "queueId": 9, "demands": [], "enableAccessToken": false, "timeoutInMinutes": 0, "jobCancelTimeoutInMinutes": 1, "condition": "succeeded()", "overrideInputs": {} }, "rank": 1, "phaseType": "agentBasedDeployment", "name": "Run on the agent", "workflowTasks": [{ "version": "4.*", "name": "Deploy Azure App Service", "refName": "", "enabled": true, "alwaysRun": false, "continueOnError": false, "timeoutInMinutes": 0, "overrideInputs": {}, "condition": "succeeded()", "inputs": { "ConnectionType": "AzureRM", "WebAppKind": "webAppContainer", "WebAppName": "azureappservice1", "DeployToSlotOrASEFlag": "false", "ResourceGroupName": "", "SlotName": "production", "DockerNamespace": "dockerusername", "DockerRepository": "mydockerimage", "DockerImageTag": "10"
} }] }] }] }

It would be very helpful if you share an example template for the same request. Please help!!!

2

2 Answers

1
votes

Azure DevOps REST API to create a release definition

According to the error message:

"Workflow of deploy job 'Run on the agent' in release pipeline stage 'development' is invalid.

We could to know the task Deploy Azure App Service in the workflowTasks is invalid, we need to provide the correct request body for that task.

As I answered your previous post How to create new build pipeline using Azure DevOps REST API, this is very difficult and error-prone, if we add a huge request body completely manually. Usually, we use REST API Definitions - Get to get the Response Body from the similar release pipeline, then we update the corresponding properties by modifying the Response Body.

As test, I add the task Deploy Azure App Service in my release pipeline, then I use the REST API:

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.0

to get the Response Body:

                "workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
                        "version": "4.*",
                        "name": "Azure App Service Deploy: xxxx",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "ConnectionType": "AzureRM",
                            "ConnectedServiceName": "xxxxx",
                            "PublishProfilePath": "$(System.DefaultWorkingDirectory)/**/*.pubxml",
                            "PublishProfilePassword": "",
                            "WebAppKind": "webApp",
                            "WebAppName": "xxxx",
                            "DeployToSlotOrASEFlag": "false",
                            "ResourceGroupName": "",
                            "SlotName": "production",
                            "DockerNamespace": "",
                            "DockerRepository": "",
                            "DockerImageTag": "",
                            "VirtualApplication": "",
                            "Package": "$(System.DefaultWorkingDirectory)/**/*.zip",
                            "RuntimeStack": "",
                            "RuntimeStackFunction": "",
                            "StartupCommand": "",
                            "ScriptType": "",
                            "InlineScript": ":: You can provide your deployment commands here. One command per line.",
                            "ScriptPath": "",
                            "WebConfigParameters": "",
                            "AppSettings": "",
                            "ConfigurationSettings": "",
                            "UseWebDeploy": "false",
                            "DeploymentType": "webDeploy",
                            "TakeAppOfflineFlag": "true",
                            "SetParametersFile": "",
                            "RemoveAdditionalFilesFlag": "false",
                            "ExcludeFilesFromAppDataFlag": "true",
                            "AdditionalArguments": "-retryAttempts:6 -retryInterval:10000",
                            "RenameFilesFlag": "true",
                            "XmlTransformation": "false",
                            "XmlVariableSubstitution": "false",
                            "JSONFiles": ""
                        }
                    }
                ]

You could use this response body, and overwrite those properties you want to change.

Where can I get taskId in Azure portal?

You could check the source code of the task from Github,it is generally on the first line of task.json. Or you can use REST API/F12 to get it.

Can we use 'AzureContainerRegistry' as artifact type in the request body?

The answer should be yes (not test it by a sample). You could add following request body in the body:

"artifacts": [
    {
        "sourceId": "xxxxxxxxxxxxxxx",
        "type": "AzureContainerRepository",
        "alias": "xxx",
        "definitionReference": {
            "connection": {
                "id": "xxxxxx",
                "name": "xxxx"
            },
            "defaultVersionType": {
                "id": "latestType",
                "name": "Latest"
            },
            "definition": {
                "id": "xx",
                "name": "xx"
            },
            "registryurl": {
                "id": "22",
                "name": "22"
            },
            "resourcegroup": {
                "id": "xx",
                "name": "xx"
            }
        },
        "isPrimary": true,
        "isRetained": false
    }
],

Hope this helps.

1
votes

I can help here. In workflowTasks You need to include the "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1" which is id of the AzureRmWebAppDeploymentV4.

"workflowTasks": [
            {
              "taskId": "497d490f-eea7-4f2b-ab94-48d9c1acdcb1",
              "version": "4.*",
              "name": "Deploy Azure App Service",
              "refName": "",
              "enabled": true,
              "alwaysRun": false,
              "continueOnError": false,
              "timeoutInMinutes": 0,
              "definitionType": null,
              "overrideInputs": {},
              "condition": "succeeded()",
              "inputs": {
                  "ConnectionType": "AzureRM",
                  "WebAppKind": "webAppContainer",
                  "WebAppName": "azureappservice1",
                  "DeployToSlotOrASEFlag": "false",
                  "ResourceGroupName": "",
                  "SlotName": "production",
                  "DockerNamespace": "dockerusername",
                  "DockerRepository": "mydockerimage",
                  "DockerImageTag": "10"

              }

Once I added that I was able to create the release definition with your request body.