Merge latest CI/CD improvements into master
This MR fixes a bug in the CI/CD code. Previously, the CI/CD script didn't explicitly check out a branch, so all deployments were from 'master'. This is fixed now and the script section is generalised and moved to the template.