Requirement is to copy the updated files of the website to the target environment (Production, Staging etc.) automatically using copy task in release manager.
It can be easily implemented by using the copy task which is internally a Robocopy operation.
Issue is that the copy task will fail, if some user is already accessing the website and at the same time this task is trying to copy the files.
This problem can be handled by implementing following steps in the given order –
- Stop the application pool
- Copy the updated web files
- Start the application pool
Step 2 above is the available copy task in TFS RM.
Step 1 and 3 can be implemented using a PowerShell script.
Here is the content of the script –
Its can be executed as - .\AppPoolStopStart.ps1 DefaultAppPool Start
Now add this to the source code in TFS and publish it in the build artifacts for the release definition.
In release definition, add the following tasks in the below order –
- Task to copy this PowerShell from the published artifacts to the target machine.
- Task to run PowerShell on Target Machines to execute the above PS script with an arguments as “Application Pool Name and the status as “Stop”.
- Other required Release Manager tasks.
- Task to run PowerShell on Target Machines to execute the above PS script with an arguments as “Application Pool Name and the status as “Start”.
On successful execution of the above release definition, it will –
- First stop the application pool.
- After successful execution of other tasks, it will finally start the application pool.
——End of Article——