Automatically merging to master when pushed by a user

Subhi Andrews March 20, 2019

We have a deployment project in Bamboo with various deployment environments in it. The environments do commit to the master branch in a particular repository. When these environments run in parallel on different agents, some of the pushes to remote on Bitbucket fails. We were wondering if we can have these environments commit to a different branch for each environment and have Bitbucket automatically merge them to master via some hook.

It's important that all the changes pushed by various environments are immediately available in the master branch.

Commits will be made by Atlassian Bamboo user. 

BTW, this discussion originally started in Bamboo and finally got  here.

https://community.atlassian.com/t5/Bamboo-questions/Pipelining-Bamboo-Deployments-into-various-environments/qaq-p/1033201?utm_campaign=mentions_reply&utm_content=post&utm_medium=email&utm_source=atlcomm#M22464

4 answers

0 votes
Subhi Andrews March 26, 2019

We sometimes have deployments running in parallel that pushes to the same repo. If we use a script task and explicitly call git command to commit and push, we see push rejected message. Here's what we see when that happens (using Bamboo VCS task):

simple 25-Mar-2019 14:02:03 Starting task 'Push changes Back to Git Deltaservicetasks' of type 'com.atlassian.bamboo.plugins.vcs:task.vcs.commit'
error 25-Mar-2019 14:02:03 Error occurred while running Task 'Push changes Back to Git Deltaservicetasks(12)' of type com.atlassian.bamboo.plugins.vcs:task.vcs.commit.
error 25-Mar-2019 14:02:03 com.atlassian.bamboo.task.TaskException: An error occurred while committing changes to repository
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.vcs.task.VcsCommitTask.execute(VcsCommitTask.java:81)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.task.TaskExecutorImpl.lambda$executeTasks$3(TaskExecutorImpl.java:319)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.task.TaskExecutorImpl.executeTaskWithPrePostActions(TaskExecutorImpl.java:252)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.task.TaskExecutorImpl.executeTasks(TaskExecutorImpl.java:319)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.task.TaskExecutorImpl.execute(TaskExecutorImpl.java:112)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.build.pipeline.tasks.ExecuteBuildTask.call(ExecuteBuildTask.java:73)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.executeBuildPhase(DefaultBuildAgent.java:203)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent.build(DefaultBuildAgent.java:175)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.lambda$waitAndPerformBuild$0(BuildAgentControllerImpl.java:131)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:185)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.v2.build.agent.BuildAgentControllerImpl.waitAndPerformBuild(BuildAgentControllerImpl.java:125)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent$1.run(DefaultBuildAgent.java:126)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.utils.BambooRunnables$1.run(BambooRunnables.java:48)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.security.ImpersonationHelper.runWith(ImpersonationHelper.java:26)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.security.ImpersonationHelper.runWithSystemAuthority(ImpersonationHelper.java:17)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.security.ImpersonationHelper$1.run(ImpersonationHelper.java:41)
error 25-Mar-2019 14:02:03  at java.lang.Thread.run(Unknown Source)
error 25-Mar-2019 14:02:03 Caused by: com.atlassian.bamboo.plugins.stash.repository.StashRepositoryException: com.atlassian.bamboo.repository.RepositoryException: Can't guess branch name for revision 401269fed2e92875571aa30182793c2e5949dcc4 when trying to perform push.
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.stash.v2.BitbucketServerWorkingCopyManager.updateRemote(BitbucketServerWorkingCopyManager.java:77)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.vcs.task.VcsCommitTask.execute(VcsCommitTask.java:74)
error 25-Mar-2019 14:02:03  ... 16 more
error 25-Mar-2019 14:02:03 Caused by: com.atlassian.bamboo.repository.RepositoryException: Can't guess branch name for revision 401269fed2e92875571aa30182793c2e5949dcc4 when trying to perform push.
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.git.NativeGitOperationHelper.pushRevision(NativeGitOperationHelper.java:139)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.git.v2.GitWorkingCopyManager.updateRemote(GitWorkingCopyManager.java:323)
error 25-Mar-2019 14:02:03  at com.atlassian.bamboo.plugins.stash.v2.BitbucketServerWorkingCopyManager.updateRemote(BitbucketServerWorkingCopyManager.java:71)
error 25-Mar-2019 14:02:03  ... 17 more
s

 

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2019

Hi @Subhi Andrews

After some discussions with @Douglas Gnoato (from Bitbucket team), we came into a conclusion that the errors you get are not caused by a limitation in Bitbucket to handle parallel requests, but a restriction in Bamboo itself. I was able to reproduce the issue, but I'm still working on troubleshooting it.

I have strong reasons to think this is a bug related to the commit/push tasks managing the same repository cache, but the investigation is not complete yet. As soon I have news to share I'll post them here.

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 1, 2019

Hi @Subhi Andrews

Let me try to explain the issue you are facing after some tests I've run.

Bitbucket is capable of handling multiple connections at the same time for pushes, which does not mean they will succeed. Every time you try to push code to a repository that has changes you didn't fetch before will cause the push to be rejected. That will happen often when you try to use multiple environments with a schedule trigger. They will all start together and one will eventually push changes before and the next to try will need to fetch and merge the changes before attempting a new push. This is to explain basically why the schedule trigger is not a good option here. Unless you use a script to decide what to do when the push is rejected, solving this issue.

I also tested the chain trigger which was surprisingly not working when multiple environments were trying to push changes to the same repository. I suppose this happens due to the way we manage the checkout tasks internally. I've open a bug report for this one: [BAM-20376] Push to same repository in more then one environment leads to "Can't guess branch name". At least this one has a workaround.

So the options available I see are:

  • Implement a script to handle the commits/pushes (handling the rejected scenario) and using the scheduled trigger
    OR
  • Use the chain trigger as described in the bug above, implementing the workaround

I hope that helps you move forward.

Like Subhi Andrews likes this
0 votes
Douglas Gnoato
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2019

Hi @Subhi Andrews 

I have read the Bamboo question and this one, but I'm still not sure what is reported when the push fails. So I'd like to take a step back and get that information just to make sure we get the details. 

With that in mind, could you please let us know the error reported when the push fails? 

With that information we can narrow down if that is related to git objects or to something else.

Cheers,

Douglas Gnoato
Atlassian Support

0 votes
Subhi Andrews March 22, 2019

No answers yet. That's really slow.

0 votes
Subhi Andrews March 20, 2019

...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events