Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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?

1 answer

1 vote
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 C
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.

Suggest an answer

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

Atlassian Community Events