Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I push code to a remote server using bamboo?

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:

  1. Created repositories and everything is properly pushing and pulling
  2. Connected Bitbucket and Bamboo successfully
  3. Installed git on all of the servers and it works like a charm from command line and gui interfaces
  4. Created a build plan that has 1 job... it checks out the code from the repo

 

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:

  • writing the command inline
  • placing it in a batch file
  • I tried including the $ before git and not
  • I tried powershell, shell with a bash shebang, and cmd.exe to no avail

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.2018-09-13 08_08_39-Gallery of Guns - GOG Development - Push to dev_ Edit job configuration - Atlass.png2018-09-13 08_09_48-Gallery of Guns - GOG Development - Push to dev 11_ Build log - Atlassian Bamboo.png

2 answers

1 accepted

1 vote
Answer accepted

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.

Hi @Rajath Veeramanchala,

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

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

Hi @Rajath Veeramanchala,

Thanks for the helpful information. I've been able to fix and am moving right along.

Cheers,

Dominic

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?

0 votes
edwin Community Leader Sep 13, 2018

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.

Hi @edwin

git is in the path already and can be run manually on the server

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

244 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you