微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

提交状态无法通过 API 在 Azure 版本中与持续部署触发器一起使用

如何解决提交状态无法通过 API 在 Azure 版本中与持续部署触发器一起使用

我们有一个 Azure 存储库,每次将某些内容推送到主分支时,它都会触发一个发布管道。 当一个 Release 被触发时,它会在 Azure Repos 中提交的右侧显示其状态(成功),如下图所示:

enter image description here

它甚至显示了哪个阶段已经被提升等等,这太棒了。使用以下 CD-Trigger 配置手动配置发布管道时,这一切正常:

enter image description here

即使在导出管道 JSON 文件并重新导入它时,一切都按预期工作。

但是,当通过 API 使用完全相同的设置创建发布时,我看不到发布的状态。触发器本身按预期工作,但提交中的状态根本不存在:

enter image description here

有人知道 Release-Pipeline.json 中的哪个确切设置负责这种状态吗?

以下是我通过 API 发送的 json 正文的某些部分,可能缺少某些内容

编辑:我想还需要一些信息。我使用 cli-tool 创建主体并发送 api 请求。这些值是模板化的。 模板从之前的 api 调用用户输入中获取其值。这是完整的模板。我根据手动配置的 relase-pipeline JSON 创建了它(工作正常并显示我想要的状态)。

{
"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"
            },"deFinition": {
                "id": "black-washed","name": "azure-pipeline-templates"
            },"project": {
                "id": "black-washed","name": "Operations"
            }
        },{
        "type": "Build","alias": "BuildPipeline","deFinitionReference": {
            "defaultVersionType": {
                "id": "latestType","name": "Latest"
            },"deFinition": {
                "id": "{{.BuildPipelineID}}","IsMultiDeFinitionType": {
                "id": "False","name": "False"
            },"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": "","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,"executionorder": 1
            }
        },"postDeployApprovals": {
            "approvals": [
                {
                    "rank": 1,"executionorder": 2
            }
        }
    },{
        "name": "test","rank": 2,"conditions": [
            {
                "name": "dev","conditionType": 2,"value": "4"
            }
        ],"isAutomated": false,"isNotificationOn": false,"approver": {
                        "displayName": null,"id": "{{.ApproverID}}"
                    }
                }
            ],{
        "name": "prod","rank": 3,"conditions": [
            {
                "name": "test","inputs": {
                            "secureFile": "black-wahsed","executionorder": 2
            }
        }
    }
],"triggers": [
    {
        "branchFilters": [
            "{{.buildrepodefaultBranch}}"
        ],"triggerType": 3
    }
]

解决方法

根据您的描述,我对其进行了测试,一切正常。

步骤:

通过 REST API Definitions - Get 获取发布定义并复制响应正文。

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

通过 REST API 创建新的发布管道 Definitions - Create

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

复制响应正文并将字段 name 重命名为 New release pipeline2,然后将其标记为请求正文。

我正在使用邮递员。

enter image description here

结果:

enter image description here

更新 1

您似乎缺少请求正文中的字段 environmentOptions 字段,其中包含控制您缺少的功能的 publishDeploymentStatus

如果不配置它或将值设置为false,您将不会在提交页面中看到发布状态。

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

结果:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?