这是有关如何使用REST API和cURL上传到Nexus的文档:https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programatically-upload-an-artifact-into-Nexus-
下面是我的C#代码,它返回一个已完成状态,但文件未上传。不知道遗失了什么。
public void uploadArtifact()
{
RestRequest request = new RestRequest("artifact/maven/content/", Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddHeader("Content-Type", "x-www-form-urlencoded");
request.AddParameter("r", "releases");
request.AddParameter("hasPom", "false");
request.AddParameter("p", "zip");
request.AddParameter("e", "zip");
request.AddParameter("g", "otpp.devops");
request.AddParameter("a", "githubSuspsendInactiveADAccounts");
request.AddParameter("v", "1.0.1");
request.AddFile("githubSuspsendInactiveADAccounts-1.0.1.zip", @"C:\\Temp\\Nexus\\githubSuspsendInactiveADAccounts-1.0.1.zip"); //Completed but not uploaded
IRestResponse response = this.restSharpAPI.Execute(this.client, request);
Console.WriteLine("Response received: {0}", response.ResponseStatus);
}
答案 0 :(得分:0)
我完成了这项工作,但还没弄明白如何添加路径:
request.AddFile("githubSuspsendInactiveADAccounts-1.0.1.zip", "githubSuspsendInactiveADAccounts-1.0.1.zip");