2

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!!!

Kumaresh Babu N S
  • 1,648
  • 5
  • 23
  • 39

2 Answers2

2

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    How to provide Azure Subscription Id in the workflow? – Kumaresh Babu N S Feb 10 '20 at 04:16
  • @KumareshBabuNS, You need manually add the Service connections* in the project settings, then add the `ConnectedServiceName` in the request body, like: `"ConnectedServiceName": "xxxxx",`, you could check it in above task body. – Leo Liu Feb 10 '20 at 04:21
  • Thanks @Leo Liu-MSFT. I will try this option. – Kumaresh Babu N S Feb 10 '20 at 04:24
  • 1
    Can we use 'AzureContainerRegistry' as artifact type in the request body? – Kumaresh Babu N S Feb 10 '20 at 04:35
  • @KumareshBabuNS, The answer should be yes (not test it by a sample), you could check mu update answer for some more details. – Leo Liu Feb 10 '20 at 05:04
  • 1
    The Azure Subscription is working by using `ConnectedServiceName` property. I got service connection issue while using Azure Container Repository. I've created service connection for ACR but it's not showing up in the list in Azure portal. Can you please advise? – Kumaresh Babu N S Feb 10 '20 at 07:18
  • @KumareshBabuNS, It should be another question, would you please open a new thread with some more info, like steps and images about it, I could not give any useful suggestion at this moment, since there is no details info about it. Thanks. – Leo Liu Feb 10 '20 at 07:44
  • 1
    Thanks @Leo Liu-MSFT. I've opened a new thread https://stackoverflow.com/questions/60146484/unable-to-get-the-service-connection-for-azure-container-registry-in-azure-devop Can you please help? – Kumaresh Babu N S Feb 10 '20 at 08:22
  • @KumareshBabuNS, Do n’t worry, I am still in the current thread, I have asked my colleagues to look at that thread, and she has reproduced and found the cause of this problem, now, she is trying to see if there is a workaround for it. Thanks for your patience, I will let you know if there are any results. – Leo Liu Feb 10 '20 at 10:20
  • Thanks @Leo Liu-MSFT – Kumaresh Babu N S Feb 10 '20 at 10:21
1

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.

Eric Smith
  • 2,340
  • 12
  • 16