How to change pipeline runner git user?

Martynas Šustavičius August 15, 2023

Problem. When my pipeline runs in our CI server using Bitbucket Runners instead of using CI git user, it uses git user: "bitbucket-pipelines" and instead of our repository, it uses "build" repository. Because of that my script fails, as it is unable to push tags into my own repository.

 

How can I change this behaviour?

2 answers

2 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2023

Hi @Martynas Šustavičius and welcome to the community!

I would like to ask for some additional information so I can better help you:

1. When you say 'user', are you referring to the user on the host machine that runs the Runner?

Or to the Bitbucket user that is used during a build to push to a Bitbucket repo?

2. What type of Runner are you using? Linux Docker, Linux Shell, MacOS, or Windows Runner?

3. It is not clear what you mean by 'instead of our repository, it uses "build" repository'.

Could you perhaps post the build log here after sanitizing any private data (replace any private/sensitive info with dummy values) and explain where in the build log you see a different repository than what you expect?

Kind regards,
Theodora

Martynas Šustavičius August 16, 2023

Hi,

1. Yes, that machine has a normal git account with access to required repositories

2. MacOS runner.

3. 

I have this shell script that executes following command in runner:

# Display current folder and git username
current_dir=$(pwd)
echo "Current dir: $current_dir"
git_username=$(git config user.name)
git_repository=$(basename $(git rev-parse --show-toplevel))
echo "Git username: $git_username. Git repository: $git_repository"

And it prints me not what I expect. It somehow sees this "bitbucket-pipelines" user and "build" repository.

I assumed that pipelines automatically checkout their original repository. We have repository called xxxxx, so I assumed, that If I setup pipelines on it, when it runs, it checks out xxxxx and starts executing pipeline from there. But it seems as it barely downloads the content of that repository without any git information.

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

Hi @Martynas Šustavičius,

Thank you for the info.

Regarding the git config user, there are three places where a git config file may be found in a system.

1. In the system-wide [path]/etc/gitconfig
2. In ~/.gitconfig
3. In the .git/config located in the clone of a repo

The values in each of these levels overwrite the ones in the previous levels.

When the repo is cloned on your machine during a Pipelines build, the .git/config in that clone has as user.name 'bitbucket-pipelines'. This will override the value that exists in the ~/.gitconfig on your machine.

Please keep in mind that this has nothing to do with access, permissions, Bitbucket users, or users of the host machine. This is the name that will be displayed as author if you make a commit during the Pipelines build in this clone.

You can change it if you add the following command in your yml file or in your script:

git config user.name "My user"


Regarding the name 'build', when running a Pipelines build with a MacOS runner, the repo will always get cloned in a directory named 'build'. The runner will try to empty the 'build' directory empty after each step finishes.

You can use the default variable $BITBUCKET_REPO_SLUG during the build if you want to get the slug of the repository. In many cases, this will be the name of the repo, except if the repo name has characters not allowed in the slug. For example, if you have a repo named a@b!-#c then the repo slug will be a-b-c and the repo URL will be https://bitbucket.org/my-workspace/a-b-c/

The repo that the Pipelines build is running for is still cloned in this 'build' directory.

Could you please explain what you mean by 'it seems as it barely downloads the content of that repository without any git information'?

If your Pipelines build is running for a branch, only that specific branch will be cloned with a default depth of 50. This is something that you can adjust in the yml file by specifying either a different number or 'full' for a full clone. Reference: https://support.atlassian.com/bitbucket-cloud/docs/git-clone-behavior/#Depth

Kind regards,
Theodora

Martynas Šustavičius August 20, 2023

I have very simple use case.

My pipelines is configured to run very simple script:

git tag "v9999"
git push --tag
Script fails because it says that I don't have permissions to push this tag, even though Mac Studio is added to repository's permission list.
I assumed it's because of that "bitbucket-pipelines" user and "build" repository, because they override actual checked out repository and Mac studio git user.
But if it's only name that's different, and shouldn't impact permissions, then I'm not sure what else could be causing this.
Norbert Csupka
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2023

Hi Martynas,

Based on the error message, I suspect you have Branch Permissions setup in the repository.

When you setup Branch Permissions only just certain users can push to the repository and unfortunately it's not possible to expose Bitbucket Pipelines user within the branch permission. We have a feature request for this:

As a workaround, I'd like to recommend you to change your remote-url (using secured environmental variables), which includes a username of a user, who has been added under the branch permission

For example: 

git remote set-url origin https://username:apppassword@bitbucket.org/workspace/repo.git

Please let us know if that helps.

0 votes
Chetan Patidar September 10, 2024

hi @Theodora Boudale ,

I'm using a Bitbucket pipeline runner instead of a self-hosted runner. During the pipeline execution, when I check the git config --list, I see the following:

  • git config user.name: bitbucket-pipelines
  • git config user.email: commits-noreply@bitbucket.org

I want to set this to my personal Git user and email. To do this, I’ve executed the following commands within the pipeline:

At the global level:

git config --global user.name "ABC"
git config --global user.email "abc@someemail.com"

At the system level:
git config --system user.name "ABC"
git config --system user.email "abc@someemail.com"

However, despite setting these values, when I check git config --list before running git clone, it still shows:

  • git config user.name: bitbucket-pipelines
  • git config user.email: commits-noreply@bitbucket.org

It seems that Bitbucket's default pipeline settings might be overriding the global and system configurations. Can you please help me resolve this issue so that my Git user and email settings are applied properly during the pipeline execution?

Thanks in advance for your assistance!




Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2024

Hi Chetan,

I see that my colleague replied to your question https://community.atlassian.com/t5/Bitbucket-questions/Need-to-set-the-our-own-git-user-in-bitbucket-pipeline-runner/qaq-p/2808051, but I'll post the answer here as well for visibility to other users may come across this post.

The git config commands you are running with the --global and the --system option change the ~/.gitconfig and [path]/etc/gitconfig. When the repo is cloned during a Pipelines build, the file .git/config inside that clone has as user.name 'bitbucket-pipelines' and as user.email 'commits-noreply@bitbucket.org'. This config in the clone of the repo overrides any values you set on the global or system level, so you need to change that one.

You can do this by running the following commands:

git config user.name "ABC"
git config user.email "abc@someemail.com"

Just a heads up, I edited the values from your post to protect your privacy.

If you have any questions, please reach out via the new question you created.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events