用于将人工制品从快照提升到发布存储库的卷曲语法
Curl syntax to use to promote artefacts from Snapshot to Release Repository
请问有人知道用于将工件从 Nexus Snapshot Repo 提升到 Release Repository 的 curl 语法吗?
据我所知没有这样的事情。您需要更改您的 pom 文件并进行部署。
不,你不能。您必须执行完整发布:mvn release:prepare release:perform
.
Nexus Pro 的暂存套件允许您通过多个步骤将部署到临时暂存存储库的发布工件提升到最终发布存储库。有一个 REST API 用于自动执行此操作,但您也可以使用 Nexus Staging Maven 插件或 Ant 任务。 Staging chapter in the Nexus documentation 有更多关于所有这些的指针。
然而,它与将 SNAPSHOT 工件提升到版本无关。这通常被视为一种不好的做法,因为它需要重写 POM 文件。
您可以绝对对所有内容使用 curl。我个人使用 NING HttpClient (v1.8.16)。
无论出于何种原因,Sonatype 令人难以置信地 难以弄清楚正确的 URL、headers 和有效负载应该是什么;我不得不嗅探流量并猜测...那里有一些勉强有用blogs/documentation,但是它要么与oss.sonatype.org
无关,要么是XML 基于(我发现它甚至不起作用)。他们方面的废话文档,恕我直言,希望未来的寻求者可以发现这个答案有用。
我不认为你可以在不生成另一个构建的情况下从 SNAPSHOT 转到 RELEASE,但是如果你创建另一个构建并直接部署到暂存存储库并从暂存 -> 发布升级,这将完成我认为你想要。
如果您发布到 oss.sonatype.org 以外的 Nexus,只需将其替换为正确的主机即可。
您感兴趣的URL
"https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish"
其中 profile
是您上传初始 POM/Jar.
时的 sonatype/nexus 个人资料 ID(例如 4364f3bbaf163
)
这是我为此编写的(CC0 许可)代码。当您上传初始 POM/Jar.
时,也会从响应中解析 repo
(例如 comdorkbox-1003
)
关闭回购:
/**
* Closes the repo and (the server) will verify everything is correct.
* @throws IOException
*/
private static
String closeRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Closing " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
推广回购:
/**
* Promotes (ie: release) the repo. Make sure to drop when done
* @throws IOException
*/
private static
String promoteRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Promoting " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/promote")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
删除回购:
/**
* Drops the repo
* @throws IOException
*/
private static
String dropRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Dropping " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/drop")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
删除签名大便:
/**
* Deletes the extra .asc.md5 and .asc.sh1 'turds' that show-up when you upload the signature file. And yes, 'turds' is from sonatype
* themselves. See: https://issues.sonatype.org/browse/NEXUS-4906
* @throws IOException
*/
private static
void deleteSignatureTurds(final String authInfo, final String repo, final String groupId_asPath, final String name,
final String version, final File signatureFile)
throws IOException {
String delURL = "https://oss.sonatype.org/service/local/repositories/" + repo + "/content/" +
groupId_asPath + "/" + name + "/" + version + "/" + signatureFile.getName();
RequestBuilder builder;
Request request;
builder = new RequestBuilder("DELETE");
request = builder.setUrl(delURL + ".sha1")
.addHeader("Authorization", "Basic " + authInfo)
.build();
sendHttpRequest(request);
builder = new RequestBuilder("DELETE");
request = builder.setUrl(delURL + ".md5")
.addHeader("Authorization", "Basic " + authInfo)
.build();
sendHttpRequest(request);
}
文件上传:
public
String upload(final File file, final String extension, String classification) throws IOException {
final RequestBuilder builder = new RequestBuilder("POST");
final RequestBuilder requestBuilder = builder.setUrl(uploadURL);
requestBuilder.addHeader("Authorization", "Basic " + authInfo)
.addBodyPart(new StringPart("r", repo))
.addBodyPart(new StringPart("g", groupId))
.addBodyPart(new StringPart("a", name))
.addBodyPart(new StringPart("v", version))
.addBodyPart(new StringPart("p", "jar"))
.addBodyPart(new StringPart("e", extension))
.addBodyPart(new StringPart("desc", description));
if (classification != null) {
requestBuilder.addBodyPart(new StringPart("c", classification));
}
requestBuilder.addBodyPart(new FilePart("file", file));
final Request request = requestBuilder.build();
return sendHttpRequest(request);
}
编辑1:
如何获取回购activity/status
/**
* Gets the activity information for a repo. If there is a failure during verification/finish -- this will provide what it was.
* @throws IOException
*/
private static
String activityForRepo(final String authInfo, final String repo) throws IOException {
RequestBuilder builder = new RequestBuilder("GET");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/repository/" + repo + "/activity")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.build();
return sendHttpRequest(request);
}
请问有人知道用于将工件从 Nexus Snapshot Repo 提升到 Release Repository 的 curl 语法吗?
据我所知没有这样的事情。您需要更改您的 pom 文件并进行部署。
不,你不能。您必须执行完整发布:mvn release:prepare release:perform
.
Nexus Pro 的暂存套件允许您通过多个步骤将部署到临时暂存存储库的发布工件提升到最终发布存储库。有一个 REST API 用于自动执行此操作,但您也可以使用 Nexus Staging Maven 插件或 Ant 任务。 Staging chapter in the Nexus documentation 有更多关于所有这些的指针。
然而,它与将 SNAPSHOT 工件提升到版本无关。这通常被视为一种不好的做法,因为它需要重写 POM 文件。
您可以绝对对所有内容使用 curl。我个人使用 NING HttpClient (v1.8.16)。
无论出于何种原因,Sonatype 令人难以置信地 难以弄清楚正确的 URL、headers 和有效负载应该是什么;我不得不嗅探流量并猜测...那里有一些勉强有用blogs/documentation,但是它要么与oss.sonatype.org
无关,要么是XML 基于(我发现它甚至不起作用)。他们方面的废话文档,恕我直言,希望未来的寻求者可以发现这个答案有用。
我不认为你可以在不生成另一个构建的情况下从 SNAPSHOT 转到 RELEASE,但是如果你创建另一个构建并直接部署到暂存存储库并从暂存 -> 发布升级,这将完成我认为你想要。
如果您发布到 oss.sonatype.org 以外的 Nexus,只需将其替换为正确的主机即可。
您感兴趣的URL
"https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish"
其中 profile
是您上传初始 POM/Jar.
4364f3bbaf163
)
这是我为此编写的(CC0 许可)代码。当您上传初始 POM/Jar.
时,也会从响应中解析repo
(例如 comdorkbox-1003
)
关闭回购:
/**
* Closes the repo and (the server) will verify everything is correct.
* @throws IOException
*/
private static
String closeRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Closing " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
推广回购:
/**
* Promotes (ie: release) the repo. Make sure to drop when done
* @throws IOException
*/
private static
String promoteRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Promoting " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/promote")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
删除回购:
/**
* Drops the repo
* @throws IOException
*/
private static
String dropRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {
String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Dropping " + nameAndVersion + "'}}";
RequestBuilder builder = new RequestBuilder("POST");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/drop")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.setBody(repoInfo.getBytes(OS.UTF_8))
.build();
return sendHttpRequest(request);
}
删除签名大便:
/**
* Deletes the extra .asc.md5 and .asc.sh1 'turds' that show-up when you upload the signature file. And yes, 'turds' is from sonatype
* themselves. See: https://issues.sonatype.org/browse/NEXUS-4906
* @throws IOException
*/
private static
void deleteSignatureTurds(final String authInfo, final String repo, final String groupId_asPath, final String name,
final String version, final File signatureFile)
throws IOException {
String delURL = "https://oss.sonatype.org/service/local/repositories/" + repo + "/content/" +
groupId_asPath + "/" + name + "/" + version + "/" + signatureFile.getName();
RequestBuilder builder;
Request request;
builder = new RequestBuilder("DELETE");
request = builder.setUrl(delURL + ".sha1")
.addHeader("Authorization", "Basic " + authInfo)
.build();
sendHttpRequest(request);
builder = new RequestBuilder("DELETE");
request = builder.setUrl(delURL + ".md5")
.addHeader("Authorization", "Basic " + authInfo)
.build();
sendHttpRequest(request);
}
文件上传:
public
String upload(final File file, final String extension, String classification) throws IOException {
final RequestBuilder builder = new RequestBuilder("POST");
final RequestBuilder requestBuilder = builder.setUrl(uploadURL);
requestBuilder.addHeader("Authorization", "Basic " + authInfo)
.addBodyPart(new StringPart("r", repo))
.addBodyPart(new StringPart("g", groupId))
.addBodyPart(new StringPart("a", name))
.addBodyPart(new StringPart("v", version))
.addBodyPart(new StringPart("p", "jar"))
.addBodyPart(new StringPart("e", extension))
.addBodyPart(new StringPart("desc", description));
if (classification != null) {
requestBuilder.addBodyPart(new StringPart("c", classification));
}
requestBuilder.addBodyPart(new FilePart("file", file));
final Request request = requestBuilder.build();
return sendHttpRequest(request);
}
编辑1:
如何获取回购activity/status
/**
* Gets the activity information for a repo. If there is a failure during verification/finish -- this will provide what it was.
* @throws IOException
*/
private static
String activityForRepo(final String authInfo, final String repo) throws IOException {
RequestBuilder builder = new RequestBuilder("GET");
Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/repository/" + repo + "/activity")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Basic " + authInfo)
.build();
return sendHttpRequest(request);
}