GitHub Actions后续Job无法找到已上传Artifact问题求助
GitHub Workflow中第二个Job无法找到已上传Artifact的问题排查
问题场景
同一个GitHub Workflow里配置了两个Job:
- build Job:成功生成并上传了Artifact,执行日志如下:
Run actions/upload-artifact@v4 With the provided path, there will be 58 files uploaded Artifact name is valid! Root directory input is valid! Beginning upload of artifact content to blob storage Uploaded bytes 6049904 Finished uploading artifact content to blob storage! SHA256 hash of uploaded artifact zip is 234760fcd4148780c7f4cbb3a0296eca3a3c5ae0d54457fbd5d2f97c7411d00a Finalizing artifact upload Artifact DIS_1.0.5.zip successfully finalized. Artifact ID 1366404513 Artifact DIS_1.0.5 has been successfully uploaded! Final size is 6049904 bytes. Artifact ID is 1366404513 Artifact download URL: https://github.com/my-company-url/DIS.API/actions/runs/8466719969/artifacts/1366404513
- publish-docker-image Job:无论指定Artifact名称还是尝试下载所有Artifact,都无法找到目标文件,执行日志如下:
Run actions/download-artifact@v3 No artifact name specified, downloading all artifacts Creating an extra directory for each artifact that is being downloaded Unable to find any artifacts for the associated workflow There were 0 artifacts downloaded Artifact download has finished successfully
完整Workflow脚本
name: build-and-deploy # todo: delete this and use the one below on: [workflow_dispatch] # todo: use this and delete the one above # on: # push: # branches: ["main"] # pull_request: # branches: ["main"] env: DOTNET_INSTALL_DIR: "./.dotnet" VERSION: 1.0.${{ github.run_number }} PACKAGE_STORE_NAME: Nexus # Package store name in the nuget.config file. PACKAGE_STORE_URI: https://nexus.milestone.dev # The URI PACKAGE_STORE_REPO: experimental-nuget # and repo BUILD_CONFIGURATION: -c Release jobs: build: runs-on: gha-runner-scale-set-linux steps: - uses: actions/checkout@v3 - name: Apt update run: sudo apt-get update - name: Install CURL run: sudo apt-get install -y curl - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: 8.0.x - name: Update Nuget Source run: dotnet nuget update source nexus --username ${{secrets.NEXUS_PIPELINE_SERVICE_TOKEN_USER}} --password ${{ secrets.NEXUS_PIPELINE_SERVICE_TOKEN_PASSWORD}} --store-password-in-clear-text - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build ${{ env.BUILD_CONFIGURATION }} --no-restore - name: Test run: dotnet test ${{ env.BUILD_CONFIGURATION }} --no-build --verbosity normal - name: Dotnet Publish API if: github.ref == 'refs/heads/main' run: dotnet publish ./DIS.Web/DIS.Web.csproj ${{ env.BUILD_CONFIGURATION }} --no-build -o ./publish - name: "Upload Artifact" if: github.ref == 'refs/heads/main' uses: actions/upload-artifact@v4 with: name: DIS_${{ env.VERSION }} path: ./publish retention-days: 5 publish-docker-image: runs-on: gha-runner-scale-set-linux needs: build steps: - name: Download Artifact uses: actions/download-artifact@v3 with: name: DIS_${{ env.VERSION }} - name: List Artifact Contents run: ls -R
可能的原因分析
- 分支匹配条件限制:上传Artifact的步骤添加了
if: github.ref == 'refs/heads/main'判断,但当前Workflow通过workflow_dispatch手动触发时,若触发分支不是main,github.ref就不满足条件,导致上传步骤直接被跳过。即使第一个Job日志显示上传成功,也需要确认触发Workflow时的分支是否为main。 - Action版本兼容性:上传使用
actions/upload-artifact@v4,下载使用actions/download-artifact@v3,虽然官方标注兼容,但仍可能存在版本适配问题,建议统一两个Action的版本(比如都使用v4)。 - 自托管Runner环境问题:当前使用的是自托管Runner(
gha-runner-scale-set-linux),可能存在缓存或权限异常,导致Artifact无法跨Job读取。可以临时切换为GitHub托管Runner(如ubuntu-latest)测试是否解决问题。 - 版本变量一致性问题:
VERSION变量依赖github.run_number,若两个Job的该变量值出现不一致(概率极低),会导致下载时指定的Artifact名称与上传的不匹配。可在第二个Job中添加步骤打印VERSION变量值,验证是否与上传的Artifact名称一致。
内容的提问来源于stack exchange,提问作者Dobromir Ivanov
相关产品推荐
相关产品推荐

