以编程方式创建Azure DevOps工件

问题描述 投票:1回答:1

需要创建Azure DevOps GitHub Artifact。我正在使用.Net客户端库,并尝试了以下代码。

var artifactMetaData = new ArtifactMetadata { Alias = "ArtiAlias", InstanceReference = new BuildVersion { Id = "32q42324QQe1" } };

我在这里引用的ID是Git Repo的提交ID。

我可以使用上面的代码成功创建Build Artifacts,但它没有创建GitHub Artifacts。

任何帮助将不胜感激。

azure-devops azure-pipelines azure-artifacts
1个回答
0
投票

能够使用Postman检查REST API调用,并与REST API对象相同(在请求正文中)创建ArtifactMetaData对象。然后问题解决了。

REST API请求正文,

{
  "alias": "MyRepo",
  "instanceReference": {
                "id": "r32283026ewec1c63b0842a58w2aa0a690a58265",
                "name": "r3228302",
                "sourceBranch": "feature/my-feature-branch",
                "commitMessage": "My commit message"
            }
}

我创建的C#对象,

var artifactMetadata = new ArtifactMetadata
                    {
                        Alias = "MyRepo",
                        InstanceReference = new BuildVersion
                        {
                            Id = "r32283026ewec1c63b0842a58w2aa0a690a58265",
                            Name = "r3228302",
                            SourceBranch = "feature/my-feature-branch",
                            CommitMessage = "My commit message"
                        }
};,
© www.soinside.com 2019 - 2024. All rights reserved.