Search code examples
azureazure-devopsazure-web-app-servicemsbuild-task

Copying files after the msbuild do copy to the root folder $(build.ArtifactStagingDirectory)


I want to copy some of the files from the $(Build.SourcesDirectory) to the final package in azure deployment but after the msbuild it creates a name.zip folder and rest of the files are included outside of the zip. Is there a way to include files along with the zip folder. I want the files inside the zip folder + the outside files

- task: NuGetCommand@2
          inputs:
            restoreSolution: '$(solution)'

        - task: VSBuild@1
          inputs:
            solution: '$(solution)'
            msbuildArgs: '/p:DeployOnBuild=true /p:DeleteExistingFiles=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'

        - task: CopyFiles@2
          displayName: 'Copy files'
          inputs:
            SourceFolder: 'folder/folder1/'
            Contents: '**'
            targetFolder: '$(build.ArtifactStagingDirectory)'
            OverWrite: true
            CleanTargetFolder: false

- task: AzureRmWebAppDeployment@4
          inputs:
            ConnectionType: 'AzureRM'
            appType: 'webApp'
            azureSubscription: 'subscription1'
            WebAppName: 'testapp'
            packageForLinux: '$(System.ArtifactsDirectory)/drop/*.zip'
            RemoveAdditionalFilesFlag: false
            enableCustomDeployment: true

Solution

  • I want the files inside the zip folder + the outside files

    To meet your requirement, you can extract the zip file first and then copy the required files to the corresponding folder, and finally generate a new zip file.

    You can use Extract files Task to extract the zip file and Archive files task to generate a new zip file.

    Here is an example:

    steps:
    
    xxx
    
    - task: ExtractFiles@1
      displayName: 'Extract files '
      inputs:
        archiveFilePatterns: '$(build.artifactStagingDirectory)/*.zip'
        destinationFolder: '$(build.artifactStagingDirectory)/test'
    
    - task: CopyFiles@2
      displayName: 'Copy Files to: $(build.ArtifactStagingDirectory)/test'
      inputs:
        SourceFolder: folder/folder1/
        TargetFolder: '$(build.ArtifactStagingDirectory)/test'
    
    - task: ArchiveFiles@2
      displayName: 'Archive $(build.ArtifactStagingDirectory)/test'
      inputs:
        rootFolderOrFile: '$(build.ArtifactStagingDirectory)/test'
    
    xx