本地正常的Curl命令在Azure DevOps Pipeline中报Error 55问题排查
Curl在Azure DevOps Pipeline中报Error 55的问题排查与解决
问题背景
某条Curl命令在本地执行正常,但在Azure DevOps Pipeline的bash任务中运行时报错curl: (55) Failed sending data to the peer。
本地正常运行的命令
curl --no-keepalive -X POST -H "Content-Type:multipart/form-data" -u user:pass -F "file=@output_final.xml" -F "info=@testExec.json" "https://***.***.****/rest/raven/1.0/import/execution/robot/multipart"
Azure DevOps报错日志
"C:\Program Files\Git\bin\bash.exe" /d/a/_temp/9f68be43-cac3-4312-8c3f-1c12c97dd9da.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 11 544k 0 0 11 65535 0 202k 0:00:02 --:--:-- 0:00:02 203k curl: (55) Failed sending data to the peer
关联的Azure DevOps YAML配置
trigger: - main pool: vmImage: 'windows-latest' strategy: matrix: RobotTestsWithPython3: python.version: '3.7' maxParallel: 1 steps: - task: UsePythonVersion@0 inputs: versionSpec: '$(python.version)' architecture: 'x64' - script: pip install robotframework robotframework-pabot robotframework-seleniumlibrary webdrivermanager displayName: 'Install dependencies' - powershell: | Write-Host "Robot Framework tests" robot --nostatusrc -x 'mergedxunit.xml' -N "Zeitreel CommerceCloud Tests" -d '$(Build.SourcesDirectory)\reports\' '$(Build.SourcesDirectory)\ZeitReel-Automation\TestCases\ZippySmokeTests.robot' failOnStderr: true displayName: 'Run Robot Framework Tests' continueOnError: true - powershell: | Write-Host "Rerun Failed tests" robot --nostatusrc --rerunfailed '$(Build.SourcesDirectory)\reports\output.xml' -x 'mergedxunit2.xml' --output 'output2.xml' -N "Zeitreel CommerceCloud Tests" -d '$(Build.SourcesDirectory)\reports\' '$(Build.SourcesDirectory)\ZeitReel-Automation\TestCases\ZippySmokeTests.robot' failOnStderr: true displayName: 'Rerun Failed Robot Framework Tests' continueOnError: true - powershell: | Write-Host "Run rebot to merge results" rebot --nostatusrc --merge --outputdir '$(Build.SourcesDirectory)\reports' --output 'output_final.xml' --report 'merged_report.html' --log 'merged_log.html' '$(Build.SourcesDirectory)\reports\output.xml' '$(Build.SourcesDirectory)\reports\output2.xml' failOnStderr: true displayName: 'Merge Robot Framework Test Results' continueOnError: true - powershell: | Write-Host "Run rebot to merge results xunit" rebot --nostatusrc --merge --xunit '$(Build.SourcesDirectory)\reports\outputxunit_final.xml' '$(Build.SourcesDirectory)\reports\output.xml' '$(Build.SourcesDirectory)\reports\output2.xml' failOnStderr: true displayName: 'Merge Robot Framework Test Results (xUnit)' continueOnError: true - task: PublishTestResults@2 displayName: 'Publish Test Results' continueOnError: true inputs: testResultsFiles: '$(Build.SourcesDirectory)\reports\outputxunit_final.xml' - task: PublishBuildArtifacts@1 displayName: 'Publish Robot Results' inputs: PathtoPublish: '$(Build.SourcesDirectory)\reports\' # string. Required. Path to publish. Default: $(Build.ArtifactStagingDirectory). ArtifactName: 'Robot_ResultsOutput' publishLocation: 'Container' - bash: | curl --no-keepalive -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$(Build.SourcesDirectory)\reports\output_final.xml" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart" displayName: "Upload to OSF" continueOnError: true schedules: - cron: "0 5 * * 1-5" displayName: Nightly build branches: include: - main - cron: "0 13 * * 1-5" displayName: Midday build branches: include: - main
已尝试添加--no-keepalive选项,但错误仍未解决,以下是具体的原因分析和解决办法:
原因分析与解决办法
1. Windows环境下Bash路径格式不兼容
Azure DevOps使用Windows镜像,bash任务调用Git Bash,而命令中使用Windows风格的\路径分隔符,Git Bash解析时可能出错,导致无法读取文件。
解决步骤:
将路径转换为Unix风格的/分隔符,修改curl命令:
curl --no-keepalive -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$(Build.SourcesDirectory)/reports/output_final.xml" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart"
或者用cygpath工具自动转换路径:
FILE_PATH=$(cygpath -u "$(Build.SourcesDirectory)\reports\output_final.xml") curl --no-keepalive -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$FILE_PATH" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart"
2. 文件不存在或权限异常
构建代理中生成的output_final.xml可能路径错误,或者没有读取权限,导致curl无法加载文件发送。
解决步骤:
在bash任务中先添加文件检查命令,确认文件状态:
# 查看目录下文件列表 ls -la "$(Build.SourcesDirectory)/reports/" # 读取文件前几行验证内容 head "$(Build.SourcesDirectory)/reports/output_final.xml" # 再执行curl命令 curl --no-keepalive -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$(Build.SourcesDirectory)/reports/output_final.xml" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart"
3. 网络代理或防火墙拦截
Azure DevOps构建代理的网络环境可能存在防火墙,或者需要通过代理才能访问目标服务器,导致数据发送中断。
解决步骤:
- 联系目标服务器管理员,确认Azure DevOps代理的IP是否在白名单内;
- 如果需要代理,在curl命令中添加代理参数:
curl --proxy http://your-proxy-addr:port --no-keepalive -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$(Build.SourcesDirectory)/reports/output_final.xml" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart"
4. Curl版本差异导致参数行为不同
本地和Azure DevOps环境的curl版本不一致,部分参数(如--no-keepalive)的行为存在差异。
解决步骤:
- 先查看bash环境中的curl版本:
curl --version,对比本地版本; - 尝试移除
--no-keepalive,或添加--tcp-nodelay优化连接:
curl --tcp-nodelay -X POST -H "Content-Type: multipart/form-data" -u user:pass -F "file=@$(Build.SourcesDirectory)/reports/output_final.xml" -F "info=@testExec.json" "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart"
5. 改用PowerShell执行请求
Windows环境下,PowerShell对本地文件和网络请求的支持更原生,替换bash任务为PowerShell任务可能解决问题。
解决步骤:
将原bash任务替换为以下PowerShell任务:
$filePath = "$(Build.SourcesDirectory)\reports\output_final.xml" $infoPath = "testExec.json" $uri = "https://xxx.xxxx.xxx/rest/raven/1.0/import/execution/robot/multipart" $securePass = ConvertTo-SecureString "pass" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("user", $securePass) Invoke-RestMethod -Uri $uri -Method Post -Credential $cred -Form @{ file = Get-Item $filePath info = Get-Item $infoPath }
内容的提问来源于stack exchange,提问作者Daniel M. Oliveira
相关产品推荐
相关产品推荐

