0

We have an Azure Repository which triggers a Release-Pipeline every time something is pushed to the main branch. When a Release is triggered it shows its status (succeeded) on the right side in the commits in Azure Repos like on the following Picture:

enter image description here

It even shows which stage is already promoted etc. which is awesome. This all works fine when configuring the Release Pipeline Manually with the following CD-Trigger Configuration:

enter image description here

Even when exporting the Pipeline JSON file and reimporting it everything works as expected.

However, when creating the Release with the exact same Settings via API i don't see the Status of the Release. The trigger itself works as expected but the status in the commits is simply not there:

enter image description here

Does someone know which exact Setting in the Release-Pipeline.json is responsible for this status?

Here are some parts of the json body I send via API which might be missing something?

Edit: A few more information needed i guess. I use a cli-tool to create the body and send the api request. The values are templated. The template gets its values either from previous api calls or from user inputs. Here is the complete template. I created it based on the manually configured relase-pipeline JSON (Which works fine and shows the status i want).

{
"name": "{{.BuildProjectName}}/{{.BuildServiceName}}",
"path": "\\",
"isDeleted": false,
"source": "restApi",
"releaseNameFormat": "{{.BuildServiceName}}-$(rev:r)",
"properties": {
    "DefinitionCreationSource": {
        "$type": "System.String",
        "$value": "ReleaseNew"
    },
    "IntegrateBoardsWorkItems": {
        "$type": "System.String",
        "$value": "False"
    },
    "IntegrateJiraWorkItems": {
        "$type": "System.String",
        "$value": "false"
    }
},
"artifacts": [
    {
        "sourceId":  "{{.BuildProjectID}}:{{.BuildRepoID}}",
        "type": "Git",
        "alias": "BuildRepo",
        "definitionReference": {
            "branches": {
                "id": "{{.BuildRepoDefaultBranch}}",
                "name": "{{.BuildRepoDefaultBranch}}"
            },
            "checkoutNestedSubmodules": {
                "id": "True",
                "name": "Any nested submodules within"
            },
            "defaultVersionType": {
                "id": "latestFromBranchType",
                "name": "Latest from the default branch"
            },
            "definition": {
                "id": "{{.BuildRepoID}}",
                "name": "{{.BuildServiceName}}"
            },
            "project": {
                "id": "{{.BuildProjectID}}",
                "name": "{{.BuildProjectName}}"
            }
        },
        "isPrimary": true,
        "isRetained": false
    },
    {
        "type": "Git",
        "alias": "FluxDeployScript",
        "definitionReference": {
            "branches": {
                "id": "master",
                "name": "master"
            },
            "checkoutNestedSubmodules": {
                "id": "True",
                "name": "Any nested submodules within"
            },
            "defaultVersionType": {
                "id": "latestFromBranchType",
                "name": "Latest from the default branch"
            },
            "definition": {
                "id": "black-washed",
                "name": "azure-pipeline-templates"
            },
            "project": {
                "id": "black-washed",
                "name": "Operations"
            }
        },
        "isRetained": false
    },
    {
        "type": "Build",
        "alias": "BuildPipeline",
        "definitionReference": {
            "defaultVersionType": {
                "id": "latestType",
                "name": "Latest"
            },
            "definition": {
                "id": "{{.BuildPipelineID}}",
                "name": "{{.BuildServiceName}}"
            },
            "IsMultiDefinitionType": {
                "id": "False",
                "name": "False"
            },
            "project": {
                "id": "{{.BuildProjectID}}",
                "name": "{{.BuildProjectName}}"
            }
        },
        "isRetained": false
    }
],
"environments": [
    {
        "name": "dev",
        "rank": 1,
        "conditions": [
            {
                "name": "ReleaseStarted",
                "conditionType": 1,
                "value": ""
            }
        ],
        "deployPhases": [
            {
                "rank": 1,
                "phaseType": 1,
                "name": "Agent job",
                "refName": null,
                "deploymentInput": {
                    "queueId": "{{.QueueID}}",
                    "agentSpecification": {
                        "identifier": "ubuntu-20.04"
                    }
                },
                "workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "2a6ca863-f2ce-4f4d-8bcb-15e64608ec4b",
                        "version": "1.*",
                        "name": "Download flux creds",
                        "refName": "fluxCreds",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "secureFile": "black-washed",
                            "retryCount": "8",
                            "socketTimeout": ""
                        }
                    },
                    {
                        "environment": {
                            "USER_EMAIL": "{{.ApproverMail}}",
                            "ENVIRONMENT": "$(Release.EnvironmentName)",
                            "DESCRIPTION": "$(Release.ReleaseDescription)",
                            "URL": "$(Release.ReleaseWebURL)",
                            "PROJECT": "{{.BuildProjectName}}",
                            "CONTAINER": "{{.BuildServiceName}}",
                            "TAG": "$(Release.Artifacts.BuildPipeline.BuildNumber)",
                            "REPOSITORY": "finodigital.azurecr.io",
                            "WORKLOAD_TYPE": "deployment",
                            "NAMESPACE": "{{.BuildProjectName}}",
                            "WORKLOAD_NAME": "{{.BuildProjectName}}-{{.BuildServiceName}}",
                            "USER_NAME": "{{.ApproverName}}",
                            "FLUX_CREDS": "$(fluxCreds.secureFilePath)"
                        },
                        "taskId": "6c731c3c-3c68-459a-a5c9-bde6e6595b5b",
                        "version": "3.*",
                        "name": "Bash Script",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "targetType": "filePath",
                            "filePath": "$(System.DefaultWorkingDirectory)/FluxDeployScript/flux-release.sh",
                            "arguments": "",
                            "workingDirectory": "",
                            "failOnStderr": "false",
                            "noProfile": "true",
                            "noRc": "true"
                        }
                    }
                ]
            }
        ],
        "retentionPolicy": {
            "daysToKeep": 30,
            "releasesToKeep": 3,
            "retainBuild": true
        },
        "preDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": true,
                    "isNotificationOn": false
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 1
            }
        },
        "postDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": true,
                    "isNotificationOn": false
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 2
            }
        }
    },
    {
        "name": "test",
        "rank": 2,
        "conditions": [
            {
                "name": "dev",
                "conditionType": 2,
                "value": "4"
            }
        ],
        "deployPhases": [
            {
                "rank": 1,
                "phaseType": 1,
                "name": "Agent job",
                "refName": null,
                "deploymentInput": {
                    "queueId": "{{.QueueID}}",
                    "agentSpecification": {
                        "identifier": "ubuntu-20.04"
                    }
                },
                "workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "2a6ca863-f2ce-4f4d-8bcb-15e64608ec4b",
                        "version": "1.*",
                        "name": "Download flux creds",
                        "refName": "fluxCreds",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "secureFile": "black-washed",
                            "retryCount": "8",
                            "socketTimeout": ""
                        }
                    },
                    {
                        "environment": {
                            "USER_EMAIL": "{{.ApproverMail}}",
                            "ENVIRONMENT": "$(Release.EnvironmentName)",
                            "DESCRIPTION": "$(Release.ReleaseDescription)",
                            "URL": "$(Release.ReleaseWebURL)",
                            "PROJECT": "{{.BuildProjectName}}",
                            "CONTAINER": "{{.BuildServiceName}}",
                            "TAG": "$(Release.Artifacts.BuildPipeline.BuildNumber)",
                            "REPOSITORY": "finodigital.azurecr.io",
                            "WORKLOAD_TYPE": "deployment",
                            "NAMESPACE": "{{.BuildProjectName}}",
                            "WORKLOAD_NAME": "{{.BuildProjectName}}-{{.BuildServiceName}}",
                            "USER_NAME": "{{.ApproverName}}",
                            "FLUX_CREDS": "$(fluxCreds.secureFilePath)"
                        },
                        "taskId": "6c731c3c-3c68-459a-a5c9-bde6e6595b5b",
                        "version": "3.*",
                        "name": "Bash Script",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "targetType": "filePath",
                            "filePath": "$(System.DefaultWorkingDirectory)/FluxDeployScript/flux-release.sh",
                            "arguments": "",
                            "workingDirectory": "",
                            "failOnStderr": "false",
                            "noProfile": "true",
                            "noRc": "true"
                        }
                    }
                ]
            }
        ],
        "retentionPolicy": {
            "daysToKeep": 30,
            "releasesToKeep": 3,
            "retainBuild": true
        },
        "preDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": false,
                    "isNotificationOn": false,
                    "approver": {
                        "displayName": null,
                        "id": "{{.ApproverID}}"
                    }
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 1
            }
        },
        "postDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": true,
                    "isNotificationOn": false
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 2
            }
        }
    },
    {
        "name": "prod",
        "rank": 3,
        "conditions": [
            {
                "name": "test",
                "conditionType": 2,
                "value": "4"
            }
        ],
        "deployPhases": [
            {
                "rank": 1,
                "phaseType": 1,
                "name": "Agent job",
                "refName": null,
                "deploymentInput": {
                    "queueId": "{{.QueueID}}",
                    "agentSpecification": {
                        "identifier": "ubuntu-20.04"
                    }
                },
                "workflowTasks": [
                    {
                        "environment": {},
                        "taskId": "2a6ca863-f2ce-4f4d-8bcb-15e64608ec4b",
                        "version": "1.*",
                        "name": "Download flux creds",
                        "refName": "fluxCreds",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "secureFile": "black-wahsed",
                            "retryCount": "8",
                            "socketTimeout": ""
                        }
                    },
                    {
                        "environment": {
                            "USER_EMAIL": "{{.ApproverMail}}",
                            "ENVIRONMENT": "$(Release.EnvironmentName)",
                            "DESCRIPTION": "$(Release.ReleaseDescription)",
                            "URL": "$(Release.ReleaseWebURL)",
                            "PROJECT": "{{.BuildProjectName}}",
                            "CONTAINER": "{{.BuildServiceName}}",
                            "TAG": "$(Release.Artifacts.BuildPipeline.BuildNumber)",
                            "REPOSITORY": "finodigital.azurecr.io",
                            "WORKLOAD_TYPE": "deployment",
                            "NAMESPACE": "{{.BuildProjectName}}",
                            "WORKLOAD_NAME": "{{.BuildProjectName}}-{{.BuildServiceName}}",
                            "USER_NAME": "{{.ApproverName}}",
                            "FLUX_CREDS": "$(fluxCreds.secureFilePath)"
                        },
                        "taskId": "6c731c3c-3c68-459a-a5c9-bde6e6595b5b",
                        "version": "3.*",
                        "name": "Bash Script",
                        "refName": "",
                        "enabled": true,
                        "alwaysRun": false,
                        "continueOnError": false,
                        "timeoutInMinutes": 0,
                        "definitionType": "task",
                        "overrideInputs": {},
                        "condition": "succeeded()",
                        "inputs": {
                            "targetType": "filePath",
                            "filePath": "$(System.DefaultWorkingDirectory)/FluxDeployScript/flux-release.sh",
                            "arguments": "",
                            "workingDirectory": "",
                            "failOnStderr": "false",
                            "noProfile": "true",
                            "noRc": "true"
                        }
                    }
                ]
            }
        ],
        "retentionPolicy": {
            "daysToKeep": 30,
            "releasesToKeep": 3,
            "retainBuild": true
        },
        "preDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": false,
                    "isNotificationOn": false,
                    "approver": {
                        "displayName": null,
                        "id": "{{.ApproverID}}"
                    }
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 1
            }
        },
        "postDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,
                    "isAutomated": true,
                    "isNotificationOn": false
                }
            ],
            "approvalOptions": {
                "requiredApproverCount": null,
                "releaseCreatorCanBeApprover": false,
                "autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
                "enforceIdentityRevalidation": false,
                "timeoutInMinutes": 0,
                "executionOrder": 2
            }
        }
    }
],
"triggers": [
    {
        "branchFilters": [
            "{{.BuildRepoDefaultBranch}}"
        ],
        "alias": "BuildRepo",
        "triggerType": 3
    }
]
Y-Peter
  • 47
  • 1
  • 6
  • Hi, Just checking in to see whether this issue is still blocking you now? Any update for this issue? – Vito Liu Mar 31 '21 at 09:36

1 Answers1

1

According to your description, I tested it and everything works as expected.

Steps:

Get the release definition via the REST API Definitions - Get and copy the response body.

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

Create the new release pipeline via the REST API Definitions - Create

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.1-preview.4

Copy the response body and rename the field name to New release pipeline2, then mark it as request body.

I am using PostMan.

enter image description here

Result:

enter image description here

Update1

It seems that you are missing the field environmentOptions field in the request body, which contains publishDeploymentStatus, which controls the feature you are missing.

If you do not configure it or set the value to false, you will not see the Status of the Release in the commit page.

"environmentOptions": {
                "emailNotificationType": "OnlyOnFailure",
                "emailRecipients": "release.environment.owner;release.creator",
                "skipArtifactsDownload": false,
                "timeoutInMinutes": 0,
                "enableAccessToken": false,
                "publishDeploymentStatus": false,
                "badgeEnabled": false,
                "autoLinkWorkItems": false,
                "pullRequestDeploymentEnabled": false
            },

Result:

enter image description here

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • Yeah that might work. The thing is that i create the Request-Body with a self made cli-tool where all the values are templated. We got a lot of projects and the goal is that every project can use the tool to create their release-pipelines. So i think i am missing something in the template but i cant figure out what. – Y-Peter Mar 31 '21 at 09:42
  • Hi @Y-Peter, Since you do not configure the field `publishDeploymentStatus`, you will not see the Status of the Release, I have updated the answer, you could check the Update1 and then kindly share the result here. – Vito Liu Apr 01 '21 at 03:08
  • 1
    Thats it. Don't know how that went missing in my template. Thx a lot. Sorry for explaining a simple problem so complicated – Y-Peter Apr 01 '21 at 14:34