【问题标题】:Curl syntax to use to promote artefacts from Snapshot to Release Repository用于将工件从快照提升到发布存储库的 Curl 语法
【发布时间】:2015-09-22 10:44:58
【问题描述】:

请问有人知道用于将人工制品从 Nexus Snapshot Repo 提升到 Release Repository 的 curl 语法吗?

【问题讨论】:

    标签: maven curl nexus


    【解决方案1】:

    您可以绝对将 curl 用于所有内容。我个人使用 NING HttpClient (v1.8.16)。

    无论出于何种原因,Sonatype 都难以置信地难以确定正确的 URL、标头和有效负载应该是什么;我不得不嗅探流量并猜测......那里有一些几乎有用的博客/文档,但它要么与oss.sonatype.org无关,要么它是基于XML的(我发现它没有'甚至不工作)。恕我直言,他们的垃圾文档,希望未来的寻求者可以发现这个答案很有用。

    我认为您不能在不生成另一个构建的情况下从 SNAPSHOT 转到 RELEASE,但是如果您创建另一个构建并直接部署到暂存存储库并从暂存 -> 发布进行升级,这将完成我认为您想要的。

    如果您发布到 oss.sonatype.org 以外的 Nexus,只需将其替换为正确的主机即可。

    您感兴趣的网址 "https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish"

    其中profile 是您上传初始 POM/Jar 时的 sonatype/nexus profileID(例如 4364f3bbaf163)。

    这是我为实现此目的而编写的(CC0 许可)代码。 repo(例如comdorkbox-1003)也会在您上传初始 POM/Jar 时从响应中解析出来。

    关闭回购:

    /**
     * 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);
        }
    

    EDIT1:

    如何获取 repo 的活动/状态

    /**
     * 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);
    }
    

    【讨论】:

    • 感谢您的分享。
    【解决方案2】:

    Nexus Pro 的暂存套件允许您通过多个步骤将部署到临时暂存存储库的发布工件提升到最终发布存储库。有一个 REST API 可以自动执行此操作,但您也可以使用 Nexus Staging Maven 插件或 Ant Tasks。 Staging chapter in the Nexus documentation 有更多的指针。

    但是,它与将 SNAPSHOT 工件升级到版本无关。这通常被视为一种不好的做法,因为它需要重写 POM 文件。

    【讨论】:

      【解决方案3】:

      据我所知,没有这样的事情。您需要更改您的 pom 文件并进行部署。

      【讨论】:

        【解决方案4】:

        不,你不能。您必须执行完整版本:mvn release:prepare release:perform

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-06-24
          • 2019-11-22
          • 2020-12-08
          • 1970-01-01
          • 1970-01-01
          • 2013-10-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多