Pre/Post Deployment Custom Scripts¶
You can specify what scripts to run either before deployment or after deployment. Or both. Script is any executable file, usually written as Bash shell script on Linux and Bat or Powershell files on Windows.
How to setup¶
You can specify custom pre and post deployment scripts when you are adding or editing an environment for your particular Site on SyncRelease. When you are on the page for editing/adding Environment, please scroll down to the bottom, you will see Advanced Options as seen below by clicking on it.
- You will need to enter full path to your custom script file.
- Script file you specify must has executable permission by the webserver on which SyncRelease is running.
When you want to perform some custom work on the source code before deployment begins, here is where you specify to run a script. After source code is exported from SVN but just before deployment begins, your script will be executed by SyncRelease with two parameters passed to it.
- The first parameter is the full path to the directory which contains currently exported source code.
- Second parameter is the release number the current deployment process is about to deploy.
Example shell script
#!/bin/sh EXPORT_DIRECTORY ="$1" RELEASE_NUMBER ="$2"
When applying any modification to exported source code by your pre-deployment custom script, the final output must stay in the original directory path defined by EXPORT_DIRECTORY passed as first parameter $1.
There are times when you want to perform some specific tasks after deployment is complete, such as restarting web server or application pools, refreshing the cache on remote server or running Selenium functionality test. Then, this is when you want to run a post-deployment script.
When SyncRelease executes a post-deployment script, it will receive the same parameters as pre-deployment script such as full path to directory where source code is exported, and the release number.
Setting up on Windows¶
If you are running SyncRelease on Windows operating system, you may use either Batch (*.bat) script files or Powershell (*.ps1) script files for Pre-Deployment and Post-Deployment scripts. Below are example Batch and Powershell scripts that be used as either Pre-Deployement or Post-Deployment.
Example Batch script
echo "Path to export directory is: %1" echo "Release number is: %2"
Example Powershell script
param( $exportDir = $(Read-Host "Please enter export dir"), $releaseNumber = $(Read-Host "Please enter release number") ) echo "Path to export directory is: $exportDir" echo "Release number is: $releaseNumber"