问题
I am working on Azure DevOps Build Pipeline and one of the task is to copy my dll and pdb files into a staging folder for example
Code
MyProject
Bin
Debug
MyProject.dll
MyProject.pdb
Staging
Client
Libraries
I want to use PowerShell script task and I am using inline script. When I give below it is not working
Copy-Item $(Build.Repository.LocalPath)\Code\MyProject\Bin\$(DebugBuildConfiguration)
-Destination $(ClientLibrariesFolder)
Below are my variables
Variable Name Variable Value
StagingFolder $(Build.Repository.LocalPath)\Staging
DebugBuildConfiguration Debug
ClientLibrariesFolder $(StagingFolder)\Client\Libraries
I donot get any error. But nothing happens.
SOLUTION:
I solved my issue following below
I added new variable like below
CodeLocalPath : $(Build.Repository.LocalPath)
I added Powershell task to my Azure DevOps build pipeline.
I gave Type as Inline.
In Script I gave below
$destination = "{0}" -f $env:ClientLibrariesFolder
# Copy MyProject.dll to Staging\Client\Libraries
$sourcefolder = "{0}\Code\MyProject\Bin\{1}\MyProject.dll" -f $env:CodeLocalPath, $env:DebugBuildConfiguration
"Source : {0} and Destination : {1} " -f $($sourcefolder), $($destination)
Copy-Item $($sourcefolder) -Destination $($destination)
# Copy MyProject.pdb to Staging\Client\Libraries
$sourcefolder = "{0}\Code\MyProject\Bin\{1}\MyProject.pdb" -f $env:CodeLocalPath, $env:DebugBuildConfiguration
"Source : {0} and Destination : {1} " -f $($sourcefolder), $($destination)
Copy-Item $($sourcefolder) -Destination $($destination)
回答1:
I donot get any error. But nothing happens.
What do you mean "But nothing happens"? Do you mean that no files have been copied into your Repos?
If yes, that is the correct behavior of Devops. Because this is not recommended to upload any file back to your repo.
If you set the system.debug=true
in the variables tab, you will find the log like:
##[debug]Copy-Item C:\VS2017Agent\_work\8\s\TestSample\TestSample\Bin\Debug\*.* -Destination C:\VS2017Agent\_work\8\s\TestSample\Staging\Client\Libraries'
It will not copy the file to the repos. That should be the reason why you see nothing happens.
Besides, Looking at Microsoft's documentation the descriptions are as follows:
$(Build.Repository.LocalPath)
: The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.
So, the value of this variable is pointing to the agent instead of repos.
Note: Copy-Item
in powershell should copy the files instead of a folder, try to use *.*
to include all file in the folder.
来源:https://stackoverflow.com/questions/55911755/azure-devops-pipeline-power-shell-script-copy-files-using-variables