0
votes

I want to set up CI CD for a winforms project Dot Net Framework 4.5.2 to build the project and then copy the release files to an Azure blob.

When I create a new build pipeline and select my Azure Repo the following YAML is created

# .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)'

The pipeline builds successfully

However I am having trouble setting up the Release pipeline to copy the release files to Azure blob storage.

I created a new release pipeline with an Empty Job. Then I added an Azure File Copy Task

What do I put as the source ? When I click the elipse I see I can select a myapp (Build) folder from within a Linked artifacts folder.

I was able to set up the storage and container names , but left the Blob Prefix blank.

When I run the Agent job I get an error on AzureBlob File Copy

(edited)

 ##[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

[Update] I think the issue must be to do with the Source Source property

looking at the build logs I see path names like "D:\a\1\s\blahblah" I also see

creating bin\Release

but how do I figure out what I should be putting in the Source property ?

Trying

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

No joy.

Exception from HRESULT: 0x80070003 means the system cannot find the file specified.

[Update]

The default YAML created does not included a task to publish the build "Artifacts" (Not to be confused with the Project Artifacts )

I tried adding one

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

but the task log says

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

1 Answers

2
votes

Please have a try to append the copy file and publish Build Artifacts task after VS build task in the build pipeline.

In the build pipeline:

...
- 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'

In the release pipeline:

Azure copy file source should be

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

We could get source alias from this screenshot

enter image description here

After we build successfully then we could choose the source path.

enter image description here

It works correctly on my side, I check it from the release log and azure storage container

enter image description here