Unable to push the code to Codecommit from Bitbucket using Bitbucket pipeline

Satyajit Sahoo (Consultant) October 26, 2023

Hi Team,

 

I'm unable to push the code to the codecommit repo from the bitbucket repo using the bitbucket pipeline.

Its throwing the below error. Kindly help to resolve this.

image.png

Thanks,
Satty

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 27, 2023

Hi Satty and welcome to the community!

Does this build run on a branches definition in your yml file? If not, could you please let me know what type of pipeline it is?

In case it is a branches pipeline, Pipelines clones by default the last 50 commits of the branch during a build. You can try specifying a full-depth clone for this step so that the push succeeds:

I've also seen other users report that the error occurs when they push from Bitbucket Cloud to an empty CodeCommit repository. If the CodeCommit repo is empty, you can try pushing first from your local machine and then see if subsequent builds succeed.

Kind regards,
Theodora

Satyajit Sahoo (Consultant) October 30, 2023

Hello Theodora,

Thank you so much for your response.

We are using the default pipeline property. FYI, I am including the screenshot of the pipeline below.

image.png

Also we have tried pushing the code for the same branch to the codecommit manually, even after that also we are getting the below error. Its showing as "unknown commit" after making changes and when the pipeline runs. 

Your help in resolving the issue would be greatly appreciated !!

image.png

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 30, 2023

Hi Satty,

I would like to ask some questions about your setup and your goal so I can better help you.

The default pipeline will run on a commit to every branch of the Bitbucket repo.

The git push command you have in your yml file will try to push to the development branch of the CodeCommit repo.

1. Does your CodeCommit repo have a branch named development?

2. Does your Bitbucket repo have a branch named development?

If yes, does the Bitbucket repo have other branches, apart from the development branch?

3. If both repos have a development branch, can you please check if these branches (in CodeCommit and Bitbucket) share some history? (that is, do they have some common commits already?)

4. If your Bitbucket repo has multiple branches, do you want to push the development branch of Bitbucket to the development branch of CodeCommit only?

Or do you want to push other branches of Bitbucket to respective branches of the CodeCommit repo?

Kind regards,
Theodora

Satyajit Sahoo (Consultant) October 30, 2023

Hi @Theodora Boudale ,

Thanks for the quick response.

Please find the below answers to your previously asked questions,

 

1. Does your CodeCommit repo have a branch named development?

Ans: We had development branch as we have manually pushed it to codecommit. But when we tried to sync from bitbucket it didn't work so we have created a separate branch with other name.

2. Does your Bitbucket repo have a branch named development?

If yes, does the Bitbucket repo have other branches, apart from the development branch?

Ans: Yes, the bitbucket repo have "development" branch along with other branches too.

3. If both repos have a development branch, can you please check if these branches (in CodeCommit and Bitbucket) share some history? (that is, do they have some common commits already?)

Ans: There is no commit history found in the remote repo (codecommit).

4. If your Bitbucket repo has multiple branches, do you want to push the development branch of Bitbucket to the development branch of CodeCommit only?

Or do you want to push other branches of Bitbucket to respective branches of the CodeCommit repo?

Ans: Yes, we only want to push the development branch to codecommit.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 30, 2023

Hi Satty,

Thank you for the info.

If the CodeCommit repo is now empty (no branches, no history), first try to push from local: 

1. Take a new clone of the development branch of the Bitbucket repo on your computer

git clone -b development <bitbucket-repo-url>

2. Switch to the directory of the clone (this should be the repo name)

cd <repo-name>

3. Add a second remote for the CodeCommit repo

git remote add codecommit <code-commit-repo-url>

4. Push to codecommit

git push codecommit development

 

Afterwards, change the yml file in the Bitbucket Cloud repo so that:

  • the build runs only on commits on development branch (there is no need to have a default pipeline that will run on other branches, if you don't push anything from these branches)
  • the step includes a definition for full-depth clone

 An example yml file with these changes is as follows:

 

image: atlassian/default-image:3

pipelines:
  branches:
    development:
      - step:
     clone:
   depth: full
      script:
- <command 1>
- <command 2>
- <etc...>

 

Please make sure this version of the yml exists on the development branch of the Bitbucket repo.

Then check the Pipelines build the next time you push something to development branch.

Please feel free to let me know how it goes.

Kind regards,
Theodora

Satyajit Sahoo (Consultant) October 31, 2023

Hello @Theodora Boudale

Thank you so much for the guidance, much appreaced it worked😊
Since we are using the default pipeline for every commit, the pipeline runs as expected now.

I have one final question: Could you please provide an example of a custom pipeline condition which will only run for every merge request?

 

Thanks,

Satty

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 31, 2023

Hi Satty,

It's good to hear that it works now, thank you for the update and you are very welcome!

Could you please provide an example of a custom pipeline condition which will only run for every merge request?

Do you mean a pipeline that will run when a pull request is created? Or when a pull request is merged?

 

It is possible to define a pull-requests pipeline:

This pipeline will run when a pull request is created or if its source branch gets updated. It will not run when the pull request is merged. However, when this pipeline runs, it merges the destination branch into your source branch (in the Docker container where the build runs, not in the Bitbucket repo), so the build runs on the merged code.

If you have a pipeline definition like the following, the pipeline will run when a PR with a source branch feature/* is created or updated. The branch you specify in the definition is the source branch, not the destination one.

pipelines:
pull-requests:
feature/*:
- step:
name: Build for feature branch pull request
script:
- echo "Hello, feature branch PR!"

 

There is no trigger at the moment to run a build only when a pull request is merged. The branches trigger, e.g. like in the following example, will run a build every time a commit gets pushed to a branch, but also when a pull request is merged into this branch:

pipelines:
branches:
main:
- step:
script:
- echo "Build on branch main"

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events