I'm running an on prem Bitbucket repo with an on prem Bamboo server.
I'd like to checkout code on commit and then push the changes to a different server automatically.
I'm at a loss for how to get things to function. Here is what I've done so far:
This is where I get stuck. I created a script task that uses a git push command but for some reason, bamboo is not allowing the git command to work. I tried the following:
I think I'm missing a crucial component but don't know what I don't know. Any help would be greatly appreciated.
Screens below show the log and how one instance of the command is setup.
Hi @davidsons ,
The ideal way to deploy your code to a server is using a deployment project in bamboo with scp tasks to copy your source code to the server.
When you use Source code checkout task, that will bring all your source code in to the bamboo build directory. Now you can use a SCP task after that to copy instead of using git push. It is not required to install git on your destination server.
More ideally , you should create an artifact of your source code in the bamboo plan, then create a deployment project which will pick this artifact and deploy to your destination server using SCP tasks. That way you can use this artifact to deploy to multiple environments configured under deployment project and it`s also preferred method as it is easy to trace back your releases compared to doing SCP with in the bamboo plan. You also get a rollback option by using deployment projects
Hope this helps
Regards,
Rajath.
I originally wanted to go this route but I'm running into an issue where it deploys the entire source code directory instead of the changed files only.
Could you provide an explanation for how to only package up changed files and deploy those specifically?
-or-
If that's not possible, should I be packaging the whole source as an artifact and then inside of the deployment project, telling it to only deploy the changed files while dumping the rest?
Thanks,
Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @davidsons,
You can actually package only changed code with few tweaks in bitbucket but this requirement changes based on the project. If your source code is small , then it is ideal to package it as a whole artifact and deploy so as to make it easy for rollbacks. But if your source code is large , then you can use the below method to create an artifact of only changed code :
Use this option to see only the files changed in the previous commit :
git diff --name-only HEAD HEAD^1
and you can create and archive of changed files using the below command :
git archive --output=latest_artifact.zip HEAD $(git diff --name-only HEAD HEAD^1)
To make sure this runs correctly, You have to do the following :
1. Make sure your merge strategy is Merge commit - Usually makes a merge commit every time resulting in your latest commit having changes of all the commits from source branch to target branch.For example : 3 commits from feature to dev will add 4 commits to dev with the 4th commit being merge commit and having all changes of the first 3 commits.
2. Disable Automatic merging under Branching model - Merging master to dev automatically or release/* branches to dev
3. Run the command in script task after your source code checkout task
The only problem with the merge strategy being merge commit is that it will create a large commit history and with Automatic merging it can further mess up the commit history. Also you can`t have any .zip files in your repo and in bamboo you can create an artifact of the *.zip file and then use deployment project / SCP task to copy the zip file to server.
Hope this helps. The version is 5.12 when I`m writing this answer. I have tested multiple scenarios using this method and it worked as expected. Let me know if you see any issues.
Regards,
Rajath
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the helpful information. I've been able to fix and am moving right along.
Cheers,
Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sounds fine for new and modified files, but what about deleted files in the repo ? i.e, cleaning up files deleted from the repo on the target server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @davidsons,
The issue is that Git is not in the path. Please confirm that you can run the git command manually on the server. If not, then check your path.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
git is in the path already and can be run manually on the server
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.