简体   繁体   English

Azure DevOps Pipeline - Power shell脚本,使用变量复制文件

[英]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.

相关问题 电源 shell 命令在 Azure Devops 中的 Yaml 管道中不起作用 - The power shell command do not work in Yaml pipeline in Azure Devops 如何通过Power Shell脚本和Rest API上传文件到Azure DevOps - How to upload files to Azure DevOps via Power Shell script and Rest API Azure devOps管道中的Powershell脚本 - Powershell script in azure devOps pipeline 如何使用powershell读取azure devops管道中的环境变量? - How to read environment variables in azure devops pipeline using powershell? Azure DevOps发布管道 - 在括号内使用带有管道变量的Powershell - Azure DevOps Release Pipelines - Using Powershell with Pipeline variables inside brackets 如何使用 azure devops 管道执行 sql 脚本 - how to execute sql script using azure devops pipeline 在Azure中运行Power Shell脚本 - Running a power shell script in Azure 用于在 Azure DevOps 中使用版本控制和工作 Iteam 进程创建项目的 Power shell 脚本 - Power shell script for Creating Project in Azure DevOps with Version control and work Iteam Proccess Azure DevOps 中的 PowerShell 任务中的管道变量是否可用? - Are pipeline variables available in PowerShell task in Azure DevOps? 如何使用 Power Shell 脚本访问 Azure 中的 Kudu - How to access Kudu in Azure using power shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM