Hello, greetings!
I want to share my experience setting up integration between GitLab and AppCenter through BitBucket.
The need for such integration arose during the setup for the automatic launch of UI tests for a cross-platform project on Xamarin. A detailed tutorial follows!
* I will write a separate article on automating UI testing in cross-platform conditions if the publication interests readers.
I found only one similar material. . Therefore, my article may help someone.
Task: Set up the automatic launch of UI tests on AppCenter while our team uses GitLab as the version control system.
The Problem It turned out that AppCenter does not integrate directly with GitLab. One of the solutions chosen was a workaround through BitBucket.
Steps
1. Create an empty repository on BitBucket.
I see no need to describe this in detail 🙂
2. Set up GitLab.
We need to ensure that on every push/merge to the repository, changes are also pushed to BitBucket. For this, we add a runner (or edit the existing .gitlab-ci.yml file).
First, we add commands to the before_scripts section.
- git config --global user.email "user@email"
- git config --global user.name "username"Then let's add the following command to the appropriate stage:
- git push --mirror https://username:password@bitbucket.org/username/projectname.gitIn my case, the resulting file looked like this:
before_script:
- git config --global user.email "user@email"
- git config --global user.name "username"
stages:
- mirror
mirror:
stage: mirror
script:
- git push --mirror https://****:*****@bitbucket.org/****/testapp.gitWe start the build and check that our changes/files have been uploaded to BitBucket.
* As practice has shown, setting up SSH keys is not mandatory. However, just in case, I will provide the connection setup algorithm via SSH below.
Connecting via SSH
First, you need to generate an SSH key. Many articles have been written about this. For example, you can check out .
The generated keys look something like this:

Next, the private key needs to be added as a variable in GitLab. For this, go to Settings > CI/CD > Environment Variables. Add ALL content from the file where you saved the private key. Let's call the variable SSH_PRIVATE_KEY.
* this file, unlike the file with the public key, will not have an extension.

Great, next we need to add the public key to BitBucket. For this, open the repository, go to Settings > Access Keys.

Here click Add Key and paste the content of the file with the public key (the file with the .pub extension).
The next step will be to use keys in gitlab-runner. Use these commands, but replace the asterisks with your data.
image: timbru31/node-alpine-git:latest
stages:
- mirror
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d 'r' | ssh-add - > /dev/null
- mkdir -p ~//.ssh
- chmod 700 ~//.ssh
- ssh-keyscan bitbucket.org >> ~//.ssh/known_hosts
- chmod 644 ~//.ssh/known_hosts
- git config --global user.email "*****@***"
- git config --global user.name "****"
- ssh -T git@bitbucket.org
mirror:
stage: mirror
script:
- git push --mirror https://****:****@bitbucket.org/*****/*.git3. Setting Up AppCenter
Create a new application on AppCenter.

Specify the language/platform.

Next, go to the Build section of the newly created application. Select BitBucket and the repository created in step 1.
Great, now we need to set up the build. To do this, find the gear icon.

In principle, everything is intuitive. Select the project and configuration. If necessary, enable running tests after the build. They will run automatically.
Basically, that’s all. It sounds simple, but, of course, everything doesn’t go smoothly. So I will describe some errors I encountered during the process:
‘ssh-keygen’ is not recognized as an internal or external command.
This occurs because the path to ssh-keygen.exe has not been added to the environment variables.
There are two options: add C:Program FilesGitusrbin to Environment Variables (will apply after restarting the machine), or run the console from this directory.
Did AppCenter connect to the wrong BitBucket account?
To resolve the issue, you need to unlink the BitBucket account from AppCenter. Log into the incorrect BitBucket account, go to the user profile.

Then go to Settings > Access Management > OAuth.

Click Revoke to unlink the account.

After that, you need to log in under the correct BitBucket account.
* As a last resort, also clear the browser cache.
Now go to AppCenter. Navigate to the Build section, click Disconnect BitBucket account.

When the old account is unlinked, link AppCenter again. This time to the correct account.
‘eval’ is not recognized as an internal or external command.
Use instead the command:
- eval $(ssh-agent -s)The command:
- ssh-agentIn some cases, you will either need to specify the full path to C:Program FilesGitusrbinssh-agent.exe or add this path to the system variables on the machine running the runner.
AppCenter Build is trying to start a build for a project from an outdated bitBucket repository.
In my case, the problem arose because I was working with multiple accounts. It was resolved by clearing the cache.
Source: habr.com
