[英]Azure DevOps Pipeline - Power shell script , Copy Files using Variables
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 我正在使用Azure DevOps Build Pipeline,其中一项任务是将我的dll和pdb文件复制到暂存文件夹中,例如
Code
MyProject
Bin
Debug
MyProject.dll
MyProject.pdb
Staging
Client
Libraries
I want to use PowerShell script task and I am using inline script. 我想使用PowerShell脚本任务,我使用的是内联脚本。 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. 我在我的Azure DevOps构建管道中添加了Powershell任务。
I gave Type as Inline . 我把Type作为内联 。
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.
但没有任何反应。
What do you mean " But nothing happens "? 你是什么意思“ 但没有任何反应 ”? Do you mean that no files have been copied into your Repos?
你的意思是没有文件被复制到你的Repos?
If yes, that is the correct behavior of Devops. 如果是,那就是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: 如果在变量选项卡中设置
system.debug=true
,您将找到如下日志:
##[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. 它不会将文件复制到repos。 That should be the reason why you see nothing happens.
这应该是你没有看到任何事情的原因。
Besides, Looking at Microsoft's documentation the descriptions are as follows: 此外,查看Microsoft的文档 ,描述如下:
$(Build.Repository.LocalPath)
: The local path on the agent where your source code files are downloaded.$(Build.Repository.LocalPath)
: 代理程序中下载源代码文件的本地路径 。 For example: c:\\agent_work\\1\\s By default, new build definitions update only the changed files.例如:c:\\ agent_work \\ 1 \\ s默认情况下,新构建定义仅更新已更改的文件。 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 . 因此, 此变量的值指向代理而不是repos 。
Note: Copy-Item
in powershell should copy the files instead of a folder, try to use *.*
to include all file in the folder. 注意:powershell中的
Copy-Item
应该复制文件而不是文件夹,尝试使用*.*
来包含文件夹中的所有文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.