SOLVED

ASP.NET Bundling + CI/CD - how to handle when a bundled file is deleted or renamed

Copper Contributor

We are using Azure DevOps to run a CI/CD pipeline to our various environments. We recently encountered an issue where one of the developers re-named a TypeScript file - perfectly reasonable thing to do - and then pushed his changes to BitBucket.

 

When the pipeline ran, the new output file was deployed to the target server, but because there was no cleaning process, the same file was already there with it's old name. Then subsequently when the bundle was served to the browser, it included the contents of both files and so we had instances of "Identifier 'x' has already been declared".

 

Just wondering if anyone has a neat way of handling this situation. Do you include a clean-up step in the pipeline?

 

4 Replies
Need to know couple of inputs:
- Are you using YAML way of using the CI/CD or the classic?
- whats the target of your deployment - App Service or VM?
- What task are you using to do the deployment in your pipeline? Can you describe your deployment steps in detail

Hi,

Thanks for the reply. Apologies, wasn't sure what detail I needed to include.

 

We are using a YAML file to define the pipeline steps. It is deploying to a VM. 

 

Deployment steps are as follows:

 

- stage: Deploy
  displayName: Deploy to IIS
  dependsOn: Build
  jobs:
  - deployment: DeploytoIIS
    displayName: Deploy the web application to dev environment
    environment:
      name: Development-env-02
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              downloadType: 'specific'
              downloadPath: '$(System.ArtifactsDirectory)'
          - task: IISWebAppDeploymentOnMachineGroup@0
            displayName: 'Deploy IIS Website'
            inputs:
              WebSiteName: '$(websiteName)'
              Package: '$(System.ArtifactsDirectory)\**\Zeus.zip'

 

So maybe there is a clean step we can include?

 

best response confirmed by DarrenMArdex (Copper Contributor)
Solution
Thanks for the details.

Take a look at the task documentation here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/iisweb-app-deployment-on-ma...

It has a flag called RemoveAdditionalFilesFlag. Its a boolean flag. According to the flag description from documentation - it is supposed to "Remove Additional Files at Destination". By default the value for this flag is false. So the deployment wont remove any additional files present on the server that was not present in the currently deployed deployment.

I believe this is the flag you are looking for.

Let me know If this works for you.

Hope this helps you.
That looks to be exactly what I want. Will give it a try, thanks!
1 best response

Accepted Solutions
best response confirmed by DarrenMArdex (Copper Contributor)
Solution
Thanks for the details.

Take a look at the task documentation here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/iisweb-app-deployment-on-ma...

It has a flag called RemoveAdditionalFilesFlag. Its a boolean flag. According to the flag description from documentation - it is supposed to "Remove Additional Files at Destination". By default the value for this flag is false. So the deployment wont remove any additional files present on the server that was not present in the currently deployed deployment.

I believe this is the flag you are looking for.

Let me know If this works for you.

Hope this helps you.

View solution in original post