首页 > 解决方案 > Azure DevOps 任务“cURL”在 Nexus 上的文件上传失败

问题描述

我正在尝试使用“cURL”任务从 Azure DevOps 管道上传文件 txt 或 .nupkg。但该文件未上传,并带有 1 条警告消息。

我的配置 - 使用 cURL 任务进行配置

电流输出 -

输出

预期结果 - 在 Nexus 服务器上上传文件。

请提出我所缺少的!

标签: curlazure-devopsmultipartform-datanexusmultipart

解决方案


正如您从日志中看到的错误消息:Multiple request required,这是由此任务生成的 API 引起的,不适用于 Nexus。其实在日志的第一行,就可以看到它的这个cUrl任务生成的API:

在此处输入图像描述

您可以在本地命令中对其进行测试,并且会看到它失败并出现相同的错误“ 400 Bad request”。此任务无法用于实现上传文件到 Nexus。参考其源代码文件

curlRunner.arg('-T')
        // arrayify the arg so vsts-task-lib does not try to break args at space
        // this is required for any file input that could potentially contain spaces
        curlRunner.arg([uploadFiles]);

        curlRunner.arg(url);

        if (redirectStderr) {
            curlRunner.arg('--stderr');
            curlRunner.arg('-');
        }

        if (options) {
            curlRunner.line(options);
        }

        if (username || password) {
            var userPassCombo = "";
            if (username) {
                userPassCombo += username;
            }

            userPassCombo += ":";

            if (password) {
                userPassCombo += password;
            }

            curlRunner.arg('-u');
            curlRunner.arg(userPassCombo);
        }

这是任务生成的 API 的 uri。根据 Nexus 官方文档,正确的cUrlAPI 应该如下所示:

curl -v -F r={repostory} -F e={extension} -F g={group id} -F a={artifact id} -F v={version} -F p={packaging} -F file={file path} -u {username}:{password} http://localhost:8081/repository/{repostory}/

对比这个正确的Uri,可以看到生成和使用的任务没有完成。这就是您收到警告消息的原因:400 Bad request - cUrl API 正文未完成,它需要更多的请求。

要将文件上传到 Nexus,您可以使用带有 cUrl API 脚本的命令行任务将文件上传到 Nexus 存储库管理器。

在此处输入图像描述


推荐阅读