C#Vsts ReleaseManagement列表批准并批准

时间:2019-10-28 17:05:08

标签: c# azure-pipelines-release-pipeline

我正在尝试创建一个工具,该工具可以自动启动多个构建管道以及部署管道。 我已经成功完成了构建管道,但是部署存在问题。 我可以获得部署的定义和发布,但是使用此代码我仅获得待处理的批准,同时我还希望获得已完成的批准并批准/取消 该工具希望加快devops流程的速度,因为我们正在从网站上触发构建和部署(我们批准并部署了每个管道,并且得到了很多)

var client = Connection.GetClient<ReleaseHttpClient2>();
            var releaseDefs = await client.GetReleaseDefinitionsAsync2(Config.Project);

        var ret = new List<ReleasePipelineModel>();
        foreach(var rd in releaseDefs)
        {
            var releases = await client.GetReleasesAsync2(
                Config.Project,
                definitionId: rd.Id, 
                top: 1,
                sourceBranchFilter: Constants.BranchBase + branch
            );
            var release = releases.FirstOrDefault();

            var stages = release != null ?
                await client.GetApprovalsAsync2(
                    Config.Project,
                    releaseIdsFilter: new[] { release.Id }
                )
                : null;

            ret.Add(new ReleasePipelineModel(rd)
            {
                LastRelease = release,
                Stage = stages?.FirstOrDefault()
            });
        }

        return ret.OrderBy(r => r.Name).ToList();

我希望我很清楚,谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:使用Deployment api

var deps = release != null ?
                await client.GetDeploymentsAsync(
                    Config.Project,
                    definitionId: rd.Id,
                    latestAttemptsOnly: true,
                    top: 1,
                    sourceBranch: Constants.BranchBase + branch)
                : null;