Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\$(buildStagingDirectory)
X

9

15

Building CI pipeline for .Net core APIs in VSTS. But while building getting the below error.

Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\s\$(buildStagingDirectory)

This is my build definition looks like

enter image description here

I have mentioned PathToPublish as $(buildStagingDirectory)

How do I get rid of this error??

Xavler answered 6/6, 2018 at 11:21 Comment(3)
Please unlink the Path to publish option, and then speacify Path to publish as $(Build.ArtifactStagingDirectory). And can you show the build logd here after updating your build definition?Farwell
u got the solution for this?Proportioned
My answer seems to be helping people! Could you please consider accepting it as the correct answer? Direct link to it: https://mcmap.net/q/765983/-publishing-build-artifacts-failed-with-an-error-not-found-pathtopublish-d-a-1-s-buildstagingdirectorySmail
S
16

The way I normally tackle this issue is, first, to use the PublishPipelineArtifact@0 task, instead of the deprecated PublishBuildArtifacts@1. So, in YAML, I would replace:

- task: PublishBuildArtifacts@1
  displayName: 'PublishBuildArtifacts'
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: 'drop'

for:

- task: PublishPipelineArtifact@0
  displayName: 'Publish pipeline artifact'
  inputs:
    artifactName: 'drop'
    targetPath: '$(Build.ArtifactStagingDirectory)'

If I would continue having this error, then I would set the pipeline variable system.debug to true, trigger the pipeline again, and observe the logs from the tasks that produce the artifacts I want to publish. The path should be there somewhere in those logs

Smail answered 7/5, 2020 at 14:0 Comment(4)
Doing this worked for me, however I have another existing pipeline using the apparently deprecated Publish Build Artifacts and it works. I am wondering if it has more to do with the fact that I tried adding another folder onto the pathToPublish, like I had $(Build.ArtifactStagingDirectory)\$(ProjectName) and when I used the newer task, I just left it as it was defaulted using the root directory of Pipeline.WorkspaceCentrepiece
@ccoutinho, you said it in reverse! PublishPipelineArtifact@0 is deprecated, and PublishPipelineArtifact@1 is the new one.Penult
At least I mentioned the two in my sentence :DSmail
is PublishBuildArtifacts@1 currently deprecated? I don't see that anywhere anymore.Berriman
M
8

I just encounted the exact same error.

Cause

After setting the system.debug variable to true, it revealed that the publish task actually performs a zip of the output folder (which by default is $(build.artifactstagingdirectory)) and places this 1 level higher in the directory structure. It then proceeds to delete the actual folder itself! I'm not sure if this is intended at all or a bug.

Workaround

After observing the above, I simply had the output of the publish task write to $(build.artifactstagingdirectory)\artifact and the resulting Publish Artifact task was then happy to pick up the zip file as it was still pointing to $(build.artifactstagingdirectory)

Default Publish Task output that fails

2018-06-07T02:24:17.8506434Z ##[debug]Zip Source: D:\a\1\a
2018-06-07T02:24:17.8508216Z ##[debug]Zip arguments: Source: D:\a\1\a , target: D:\a\1\a.zip
2018-06-07T02:24:18.0627499Z ##[debug]Successfully created archive D:\a\1\a.zip
2018-06-07T02:24:18.0628200Z ##[debug]rm -rf D:\a\1\a
2018-06-07T02:24:18.0629858Z ##[debug]removing directory
...
...
2018-06-07T02:24:18.3052522Z ##[error]Publishing build artifacts failed with an error: Not found PathtoPublish: D:\a\1\a

Modified output after adding extra directory

2018-06-07T02:38:59.8138062Z ##[debug]Zip Source: D:\a\1\a\artifact
2018-06-07T02:38:59.8139294Z ##[debug]Zip arguments: Source: D:\a\1\a\artifact , target: D:\a\1\a\artifact.zip
2018-06-07T02:39:00.0331460Z ##[debug]Successfully created archive D:\a\1\a\artifact.zip
2018-06-07T02:39:00.0334435Z ##[debug]rm -rf D:\a\1\a\artifact
2018-06-07T02:39:00.0336336Z ##[debug]removing directory
...
...
2018-06-07T02:39:00.4157615Z Uploading 1 files
2018-06-07T02:39:01.9425586Z ##[debug]File: 'D:\a\1\a\artifact.zip' took 1504 milliseconds to finish upload
Mommy answered 7/6, 2018 at 2:50 Comment(0)
H
3

There is no built-in variable with that name, are you looking for:

$(Build.ArtifactStagingDirectory)

See: https://learn.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts&tabs=batch

Hepler answered 6/6, 2018 at 12:0 Comment(4)
initial, this was the value set, but I was getting the same so hence I tried with the $(buildStagingDirectory)Xavler
there is one. see learn.microsoft.com/en-us/azure/devops/pipelines/build/…Prostate
Not buildstagingdirectory (no .).Hepler
use $(Build.ArtifactStagingDirectory) instead of $(Build.artifactStagingDirectory). Beware of case sensitivityMadoc
R
2

this worked for me

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: $(System.DefaultWorkingDirectory)/bin/Any CPU/Release/netcoreapp3.1
    ArtifactName: 'drop'
    publishLocation: 'Container'
Renee answered 19/2, 2020 at 13:56 Comment(0)
V
2

After you have the build folder you need to copy the file contents into Build.ArtifactStagingDirectory.

- task: CopyFiles@2
  inputs:
    contents: '/home/vsts/work/1/s/api-project/bin/Debug/net6.0/publish/**'
    targetFolder: $(Build.ArtifactStagingDirectory)

You can then publish the artifacts

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

You can then use the artifact in your release pipeline. I hope this helps I was struggling with this for a while I found help with this issue on this Link https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops

Here is the source code for my whole YAML file for reference this is a pipeline for a Monorepo.

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
  branches:
    include:
      - main
  paths:
    include: 
      - api-project/*

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

steps:
- script: |
    dotnet build --configuration $(buildConfiguration)
    dotnet publish
  displayName: 'dotnet build and publish'
  workingDirectory: './api-project'

- task: CopyFiles@2
  inputs:
    contents: '/home/vsts/work/1/s/api-project/bin/Debug/net6.0/publish/**'
    targetFolder: $(Build.ArtifactStagingDirectory)

- script: |
    ls
  displayName: check location

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
Variscite answered 4/5, 2022 at 12:10 Comment(0)
B
0

As has already been pointed out, you probably meant $(build.StagingDirectory) so with the dot. But I'm regarding that as a simple typo, as I've encountered the same problem.

The answer is that when PUBLISHING the BUILD variables don't seem to be available (despite it being shown as the example in the tool-tip). What you probably want is $(System.ArtifactsDirectory). That worked for me.

Blasius answered 21/8, 2019 at 16:14 Comment(0)
A
0

I faced the same issue while creating a CI pipeline. Finally found that the files were created in $(System.DefaultWorkingDirectory). So we need to copyfiles first to $(build.artifactstagingdirectory) before the publish build artifact task. So I added Copy Files task with Source folder as $(System.DefaultWorkingDirectory) and Target folder as $(Build.ArtifactStagingDirectory) and that resolved it.

Affiliation answered 18/7, 2023 at 6:1 Comment(0)
C
0

Try adding a publish step between the build and push to the artefact repository. By publishing it will strip all unnecessary items making the zip smaller. The step only takes about 5s to run and allows you to specify an output path.

extract of a YAML would look like this.

# ...
# Build the project 
- task: DotNetCoreCLI@2
  displayName: "Build the solution"
  inputs:
    command: 'build'
    projects: $(solution)
    arguments: '--configuration $(BuildConfiguration) --no-restore'

# Publish the build
- task: DotNetCoreCLI@2
  displayName: 'Publish the build'
  inputs:
    command: publish
    publishWebProjects: True
    projects: $(BuildParameters.RestoreBuildProjects)
    arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
    zipAfterPublish: True

# Copy Publish to artifacts storage
- task: PublishBuildArtifacts@1
  displayName: 'Copy Publish to artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
# ...
Coneflower answered 7/9, 2023 at 1:57 Comment(0)
B
0

I had a copy/paste error in my YML and was referencing a $(buildConfiguration6) that did not exist. Make sure all your variable references match up.

Barbecue answered 26/7, 2024 at 19:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.