Azure Devops:构建一个Winforms项目并将发行文件复制到Azure Blob存储

时间:2019-02-13 01:28:28

标签: azure-devops

我想为Winforms项目Dot Net Framework 4.5.2设置CI CD,以构建项目,然后将发行文件复制到Azure blob。

当我创建新的构建管道并选择Azure Repo时,将创建以下YAML

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- master

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '**\*.sln'

    feedsToUse: config

    nugetConfigPath: 'NuGet.config'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

管道成功构建

但是,我在设置发布管道以将发布文件复制到Azure blob存储时遇到麻烦。

我创建了一个带有空作业的新发布管道。 然后我添加了一个Azure文件复制任务

我应该把什么作为来源? 单击椭圆时,我看到可以从“链接的工件”文件夹中选择一个myapp(构建)文件夹。

我能够设置存储和容器名称,但是将Blob前缀留空。

运行代理作业时,我在AzureBlob文件复制上收到错误

(已编辑)

 ##[section]Starting: AzureBlob File Copy
 ==============================================================================
 Task         : Azure File Copy
 Description  : Copy files to Azure blob or VM(s)
 Version      : 2.1.3
 Author       : Microsoft Corporation
 Help         : [More Information](https://aka.ms/azurefilecopyreadme)
 ==============================================================================
 ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM\2.1.0\AzureRM.psd1 -Global
 ##[warning]The names of some imported commands from the module 'AzureRM.Websites' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
 ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM.Profile\2.1.0\AzureRM.Profile.psm1 -Global
 ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -EnvironmentName AzureCloud @processScope
 ##[command] Select-AzureRMSubscription -SubscriptionId blahblah -TenantId ***
 Uploading files from source path: 'd:\a\r1\a\_Viv2' to storage account: 'viv' in container: 'viv2' with blob prefix: ''
 ##[command] & "AzCopy\AzCopy.exe" /Source:"d:\a\r1\a\_Viv2" /Dest:"https://vivapps.blob.core.windows.net/viv2" /@:"d:\a\_temp\n40zblahblah" /XO /Y /SetContentType /Z:"AzCopy" /V:"AzCopy\AzCopyVerbose_20blahblah.log" /S
 [2019/02/13 01:26:46][ERROR] Error parsing source location "d:\a\r1\a\_Viv2": Failed to enumerate directory d:\a\r1\a\_Viv2\ with file pattern *. The system cannot find the path specified. (Exception from HRESULT: 0x80070003) For more details, please type "AzCopy /?:Source" or use verbose option /V.
 ##[error]Upload to container: 'vivj2' in storage account: 'vivapps' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme
 ##[section]Finishing: AzureBlob File Copy

[更新] 我认为问题一定与来源有关 Source property

在查看构建日志时,我看到路径名称如“ D:\ a \ 1 \ s \ blahblah” 我也看到

creating bin\Release

但是如何确定应该在Source属性中输入什么?

尝试

 $(System.DefaultWorkingDirectory)/_Viv2/bin/Release

不高兴。

HRESULT异常:0x80070003表示系统找不到指定的文件。

[更新]

创建的默认YAML不包括发布构建“工件”的任务(请勿与Project Artifact混淆)

我尝试添加一个

   - task: PublishBuildArtifacts@1    
  displayName: 'Publish Artifact: drop'
  inputs:
  PathtoPublish: '$(build.artifactstagingdirectory)'
  artifactName: drop

但是任务日志显示

##[warning]Directory 'D:\a\1\a' is empty. Nothing will be added to build artifact 'drop'

1 个答案:

答案 0 :(得分:1)

请尝试在构建管道中的VS构建任务之后附加复制文件并发布“构建工件”任务。

在构建管道中:

...
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: CopyFiles@2
  displayName: 'Copy Files'
  inputs:
    SourceFolder: '$(build.sourcesdirectory)'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

在发布管道中:

Azure复制文件源应为

$(System.DefaultWorkingDirectory)/{Source alias}/drop/xx/xxx/bin/Release

我们可以从此屏幕截图中获取源别名

enter image description here

构建成功后,我们可以选择源路径。

enter image description here

它在我这边正常工作,我从发布日志和天蓝色的存储容器中对其进行了检查

enter image description here