You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中DownloadBuildArtifacts下载JAR仅4K的问题求助

问题描述

我在Azure DevOps流水线中配置了将Maven构建的61MB JAR文件发布为流水线构件,发布过程显示正常。但后续容器化阶段使用DownloadBuildArtifacts任务下载构件时,尽管任务显示下载成功,实际下载的JAR文件仅4K,导致Docker构建的容器因无效JAR无法启动。直接从DevOps UI下载该构件可正常运行,切换构件类型后问题依旧。

流水线配置如下:

stages:
  - stage: Build
    displayName: Run a Maven build and publish code coverage
    jobs:
      - job: Build
        steps:
          - checkout: self
            persistCredentials: "true"
          - task: Maven@4
            displayName: Compile project
            inputs:
              mavenPomFile: "pom.xml"
              goals: "verify"
              jdkVersionOption: "1.21"
          ... publish test coverage ...
          - task: PublishBuildArtifacts@1
            condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'))
            inputs:
              PathtoPublish: '$(Pipeline.Workspace)/s/target/api-2.0.0.jar'
              ArtifactName: 'api.jar'
              publishLocation: 'Container'
            displayName: "Publish API JAR"
  - stage: Containerize
    displayName: Containerize
    dependsOn: Build
    condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'))
    jobs:
      - job: Docker
        displayName: "Build a Docker container"
        steps:
          - checkout: self
            persistCredentials: "true"
            fetchDepth: "0"
          - task: DownloadBuildArtifacts@1
            inputs:
              buildType: 'current'
              downloadType: 'single'
              artifactName: 'api.jar'
              downloadPath: '$(Pipeline.Workspace)/s/target/api-2.0.0.jar'
              checkDownloadedFiles: true
            displayName: "Get JAR."
          - script:  ... extract a version number ...
            displayName: "Bump Version"
            name: Version
          - task: Docker@2
            inputs:
              repository: $(containerRepo)
              containerRegistry: $(containerRegistry)
              tags: $(Version.version)
            displayName: "Build and Push Container"
          ... final tasks ...

辅助信息:

  • 流水线构件截图:已发布的构件api.jar
  • PublishBuildArtifacts任务输出:Publish任务输出
  • DownloadBuildArtifacts任务输出:显示下载61MB的任务输出
问题原因

核心错误在于DownloadBuildArtifacts任务的downloadPath参数配置错误:该参数要求传入目录路径,但你直接指定了具体的文件名。当任务检测到目标不是目录时,会将整个构件包重命名为你指定的文件名,导致实际下载的是包含原始JAR的构件容器(而非JAR文件本身),所以大小仅4K。

解决方案

修改DownloadBuildArtifacts任务的downloadPath为目录路径,后续步骤中引用该目录下的JAR文件:

- task: DownloadBuildArtifacts@1
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'api.jar'
    downloadPath: '$(Pipeline.Workspace)/downloads' # 修改为目录路径
    checkDownloadedFiles: true
  displayName: "Get JAR."

之后在Docker构建步骤中,引用正确的JAR路径:$(Pipeline.Workspace)/downloads/api.jar/api-2.0.0.jar

额外验证建议
  • 在下载任务后添加脚本步骤,验证文件大小和完整性:
ls -lh $(Pipeline.Workspace)/downloads/api.jar/
  • 确认Dockerfile中COPY的路径与下载后的JAR路径完全一致。

内容的提问来源于stack exchange,提问作者prozaak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 03:21:09