Scripted Git Branch Deployment with Jenkins
When working with git, normally work is done on a branch then merged onto master. However, it is often desired or required that someone else take a look at it before putting it on master. The process of deploying your branch to a test environment is oftentimes manual / time consuming. It does not have to be that way. It can be as simple as ‘git push; ./deploy.sh;’ using remotely triggered parameterized Jenkins builds. Despite the overly verbose description, the setup is actually not time consuming. In the following section, I am making the assumption that you already have Jenkins build that deploys master to the test environment.
- Firstly, create a new Jenkins build cloned from your normal deploy job for master.
- Mark it as parameterized.
- Mark it as remotely triggered.
- Save the configuration.
- Finally, write the deploy script. Something like this:
#!/bin/bash branchName=$(git symbolic-ref --short HEAD) echo "Deploying $branchName to test environment" curl "JENKINS_URL/job/deploy-branch/build?token=26a75277-384c-4a56-9848-3c10df6d4697&BRANCH_NAME=$branchName"