1

I have the following build pipeline:

pool:
  name: Azure Pipelines
  demands:
  - npm
  - msbuild

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    workingDir: Project123/Angular
    verbose: false
    
steps:
- task: Npm@1
  displayName: 'npm custom: angular build'
  inputs:
    command: custom
    workingDir: Project123/Angular
    verbose: false
    customCommand: 'run-script build --prod --extractCss'

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  
steps:
- task: MSBuild@1
  displayName: '.Net build'
  inputs:
    solution: 'Project123/*.csproj'
    msbuildArchitecture: x64
    configuration: Release
    msbuildArguments: '/p:OutputPath=$(Build.ArtifactStagingDirectory)'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: Project123/Bundles
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Release'
  inputs:
    ArtifactName: Release

When we build the project from VS manually, this is the (expected) artifact we deploy:

expected

However, the YAML I have generates this artifact instead:

result

How do I accomplish the expected artifact?

I am actually surprised that AngularOutput was copied in the root of the artifact, and not Bundles...I specified in the copy task to copy the Bundles folder , which would contain the AngularOutput...

Cataster
  • 3,081
  • 5
  • 32
  • 79

1 Answers1

3

Since I do not know the .csproj configuration, just provide a workaround based on the screenshot.

Don't need this Angular folder in this artifact

These Web.Debug and Web.Release are unneeded in the artifact

Add task power shell and delete the folder and files via below script

#Delete Angular folder and files
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Angular''      
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Debug.configure''    
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Release.configure''

Those dlls, .pdb, .xml and .configure files are not needed here.

There needs to be a 'Bundles' directory here which is generated by the angular build task

Check this Copy files task, these files in the folder Project123/Bundles, right?

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: Project123/Bundles
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

We need to change the Copy file task as below:

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: Project123/Bundles
    TargetFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Bundles'

It will save these files in the folder Bundles instead of root.

This AngularOutput folder needs to be located under 'Bundles' directory inside 'Project123' folder above

We could copy the folder to project123 folder and then publish the artifact.

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.ArtifactStagingDirectory)/AngularOutput'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/AngularOutput'

You could run below YAML build and check the result.

pool:
  name: Azure Pipelines
  demands:
  - npm
  - msbuild

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    workingDir: Project123/Angular
    verbose: false
    
- task: Npm@1
  displayName: 'npm custom: angular build'
  inputs:
    command: custom
    workingDir: Project123/Angular
    verbose: false
    customCommand: 'run-script build --prod --extractCss'

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  
- task: MSBuild@1
  displayName: '.Net build'
  inputs:
    solution: 'Project123/*.csproj'
    msbuildArchitecture: x64
    configuration: Release
    msbuildArguments: '/p:OutputPath=$(Build.ArtifactStagingDirectory)'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: Project123/Bundles
    TargetFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Bundles'

#Delete Angular folder and files
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Angular''      
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Debug.configure''    
      Remove-Item ''$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Release.configure''

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.ArtifactStagingDirectory)/AngularOutput'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/AngularOutput'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: Release'
  inputs:
    ArtifactName: Release

Update1

If the issue is delete the folder and files, please update the power shell script as below and try it again.

#Delete Angular folder and files
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Remove-Item -Path $(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Angular -Recurse -Force     
      Remove-Item -Path $(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Debug.configure -Recurse -Force  
      Remove-Item -Path $(Build.ArtifactStagingDirectory)/_PublishedWebsites/Project123/Web.Release.configure -Recurse -Force

And the test result:

enter image description here

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • Ohhh powershell? Interesting..but this wont work on ubuntu agent right? .I thought we would remove them with negation globbing in the copy task as a workaround – Cataster Apr 02 '21 at 03:38
  • I tested it on windows agent, ubuntu agent, maybe we need remove the files and folder via bash cmd? – Vito Liu Apr 02 '21 at 07:18
  • By the way, do you mind share the error log here? Or share the not work task steps here, thanks. – Vito Liu Apr 02 '21 at 07:21
  • i was thinking instead of having bash commands for different agents, if this can be done using negative globbing in the copy task it would be fantastic. as for logs, unless we enter a chat room, it wont allow me to upload in the post/comment on SO – Cataster Apr 02 '21 at 15:27
  • Hi @Cataster, I have updated the answer, please check the update1. And now, it seems that we cannot create chat room... – Vito Liu Apr 06 '21 at 07:28
  • Hi @Cataster, Just checking in to see whether this issue is still blocking you now? Any update for this issue? – Vito Liu Apr 07 '21 at 08:11
  • Hi Vito. i understood why the Web.Debug.config and Web.Release.config were there in the artifact. Its because the transformation is only supposed to happen on deployment. I had to select the XML flag in Azure App service deploy to get the transformations done, which makes sense. I was following this article https://medium.com/@dvinun/got-web-config-transformation-problem-in-your-azure-devops-953a8f29335b regarding transformations, mentioned is the deployment in dev would transform the Web.config basedon Release.config but then it transforms it a 2nd time based on debug.config.Is that the case? – Cataster Apr 07 '21 at 19:22
  • Hi @Cataster, Thanks for the sharing, I notice that you have raised a new SO ticket for the latest issue, If the initial issue is resolved, would you mind accepting it as answer? Or if you have any concern about the initial issue, feel free to share it here. Thanks. Have a nice day. – Vito Liu Apr 09 '21 at 02:40
  • Sure i accepted the answer here, thanks for your help :) could you provide insight on the new issue? https://stackoverflow.com/questions/67010948/how-to-transform-web-config-using-variables-instead-of-xml-transform-at-deployme?noredirect=1#comment118452693_67010948 – Cataster Apr 09 '21 at 04:03