DEV Community

Cover image for How to Deploy Your Branches to Umbraco Cloud Without Triggering Site Deployment
Søren Kottal
Søren Kottal

Posted on

How to Deploy Your Branches to Umbraco Cloud Without Triggering Site Deployment

Umbraco Cloud is an excellent hosting platform for most Umbraco projects. Built on Azure Web Apps, it provides a ready-to-use environment that allows you to start your project within minutes. One of its primary features is the automatic deployment of your code each time you commit to the Git repository, focusing mainly on the master branch.

However, a downside is that deployments are triggered for all branches you commit to, even though only the master branch gets built. This can result in unnecessary waiting times for unrelated code builds, which can be frustrating.

Several issues related to this behavior have been reported on the Cloud issue tracker, including:

If other aspects of Umbraco Cloud are causing issues, consider posting them on the issue tracker to help facilitate improvements.

Customizing Deployment Behavior with Git Hooks

Since Umbraco Cloud is hosted on Microsoft Azure, you have access to the Kudu tool for advanced hosting tasks. Kudu allows you to view the remote Git repository and add or modify Git hooks as necessary.

The default auto-deployment process operates through the post-receive Git hook, which executes a Kudu command upon every push, irrespective of the branch:

#!/bin/sh
read i
echo $i > pushinfo
"$KUDU_EXE" "$KUDU_APPPATH" "$KUDU_MSBUILD" "$KUDU_DEPLOYER"
Enter fullscreen mode Exit fullscreen mode

To avoid triggering deployments for non-master branches, you can modify this hook to check the branch before executing the deployment script. Here is the modified post-receive hook:

#!/bin/sh
read i
echo $i > pushinfo

# Read input data from Git and determine the branch
while read oldrev newrev refname
do
    # Proceed with deployment only for the master branch
    if [ "refs/heads/master" = "$refname" ]; then
        echo "$oldrev $newrev $refname" > pushinfo
        "$KUDU_EXE" "$KUDU_APPPATH" "$KUDU_MSBUILD" "$KUDU_DEPLOYER"
    fi
done
Enter fullscreen mode Exit fullscreen mode

By implementing this change, pushes to work-in-progress branches complete quickly, significantly reducing waiting times. This allows you to focus on development without the interruption of unnecessary build processes.

Top comments (0)