Azure DevOps Pipeline-Power Shell脚本,使用变量复制文件 [英] Azure DevOps Pipeline - Power shell script , Copy Files using Variables
问题描述
我正在研究Azure DevOps构建管道,其中一项任务是将dll和pdb文件复制到临时文件夹中
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
我想使用PowerShell脚本任务,并且正在使用内联脚本. 当我在下面给它时不起作用
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)
下面是我的变量
Variable Name Variable Value
StagingFolder $(Build.Repository.LocalPath)\Staging
DebugBuildConfiguration Debug
ClientLibrariesFolder $(StagingFolder)\Client\Libraries
我没有收到任何错误.但是什么也没发生.
I donot get any error. But nothing happens.
解决方案:
我在下面解决了我的问题
I solved my issue following below
我添加了如下新变量
CodeLocalPath : $(Build.Repository.LocalPath)
我将Powershell任务添加到了我的Azure DevOps构建管道中.
I added Powershell task to my Azure DevOps build pipeline.
我将Type设置为 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)
推荐答案
我没有收到任何错误.但是什么也没发生.
I donot get any error. But nothing happens.
您是什么意思"但是什么也没发生"?您是说没有文件被复制到您的Repos中吗?
What do you mean "But nothing happens"? Do you mean that no files have been copied into your Repos?
如果是,那是Devops的正确行为.因为不建议您将任何文件上传回您的仓库.
If yes, that is the correct behavior of Devops. Because this is not recommended to upload any file back to your repo.
如果您在变量标签中设置了system.debug=true
,则会找到类似以下内容的日志:
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.
此外,查看 Microsoft的文档的说明如下:
Besides, Looking at Microsoft's documentation the descriptions are as follows:
$(Build.Repository.LocalPath)
:代理上的本地路径,其中 您的源代码文件已下载.例如:c:\ agent_work \ 1 \ s 默认情况下,新的构建定义仅更新更改的文件.你 可以在存储库"选项卡上修改文件的下载方式.
$(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.
因此,此变量的值是指向代理而不是存储库.
注意:Powershell中的Copy-Item
应该复制文件而不是文件夹,请尝试使用*.*
将所有文件包括在文件夹中.
Note: Copy-Item
in powershell should copy the files instead of a folder, try to use *.*
to include all file in the folder.
这篇关于Azure DevOps Pipeline-Power Shell脚本,使用变量复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!