When creating release and deployment builds it commonly desired to tag the commit that was built. For example, the Maven release plugin does this automatically. For projects that don't use Maven we need a way to tag the release code to avoid manual steps.
It is also useful to build from a Git tag. For example, when you need to redeploy a release artifact from the past that is not present in Bamboo.
- Add a build step that will tag the currently checked out commit.
- Add the ability to select Git tags for build steps.
- Make this work in Git repositories hosted in Stash and BitBucket as well.
- Configure Source Code Checkout task in the Build Plan to checkout source.git into a directory for building the code
- Add another Source Code Checkout task in the Build Plan at the bottom of the task to checkout deploy.git into another directory
- With this deploy.git, check what is the latest changeset/revision (probably “git log -1”) with a Script task to save the changeset/revision into a file
- Create an Artifact for this file in step 3
- In the environment task, use Script task to read this file in step 3 and perform Git checkout with it in the same Script task
With this workaround, the deployment in other environment or rollback will be able to perform Git checkout on the same changeset/revision depending on the Artifact.
NOTE: For this approach you will need to setup a private key on remote agent(s) so the agent will have permission to access the repository directly. This is because the credentials stored in the Bamboo server aren't available to the script task as it is executed by the 'bamboouser' on the remote agent.