'How to copy Azure DevOps files to other physical network folder
In Azure DevOps, I want to copy files from the bin folder to some network path folder, lets say \server\folder1\folder2.
I tried it with copy task but it is not allowing me to give this \server\folder1\folder2 physical path as its targetFolder. Here is my Copy task I've tried.
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
contents: '**\bin\**'
targetFolder: '\\server\folder1\folder2'
This task is failed.
Also I tried to copy through the PowerShell task which is below:
- task: PowerShell@2
inputs:
targetType: 'filePath'
filePath: $(System.DefaultWorkingDirectory)\CopyBuildOutput.ps1
arguments: >
-Source "**\bin\"
-Destination "\\server\folder1\folder2"
displayName: 'Copy Build Output Files'
And I have this script in the CopyBuildOutput.ps1 file.
param ($Source, $Destination)
Write-Host "$Source, $Destination"
$TimeStamp = get-date -f yyyyMMddhhmm
$Destination = $Destination + $TimeStamp
New-Item -ItemType directory -Path $Destination -Force
Copy-Item -Path $Source\*.* -Destination $Destination -Force
This also failed with this below error.
New-Item : The network path was not found
At D:\a\1\s\CopyBuildOutput.ps1:5 char:1
+ New-Item -ItemType directory -Path $Destination -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (\\Ncm-sparta\ho...Gen202204120929:String) [New-Item], IOException
+ FullyQualifiedErrorId : CreateIntermediateDirectoriesIOError,Microsoft.PowerShell.Commands.NewItemCommand
##[error]PowerShell exited with code '1'.
I'm not sure how I can copy few files to the outside of DevOps. Please guide me how this can be achieved.
Appreciate your help on this. Thank you in advance.
Solution 1:[1]
AFAIK, to resolve the error "New-Item : The network path was not found" try modifying the snippet like below:
steps:
- task: CopyFiles@2
inputs:
contents: '**\bin\**'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
Otherwise,
- If you want to copy bin folder to local path, use this folder to publish your build artifacts with the Copy files and Publish build artifacts tasks.
Note: Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable. This directory is purged before each new build, so you don't have to clean it up yourself.
- This will copy files to artifact and publish artifact and run the pipeline. Create release -> add artifact -> Go to task -> Select your artifact in your folder -> Save.
References :
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RukminiMr-MT |
