Trem, hello!
I want to tell you about my experience of setting up GitLab and AppCenter integration via BitBucket.
The need for such integration arose during the setup of automatic launch of UI tests for a cross-platform project on Xamarin. Detailed tutorial under the cut!
* I will write a separate article about automating UI testing in cross-platform conditions if the public is interested.
I dug up only one similar material
Task: Set up UI tests to run automatically on AppCenter while our team uses GitLab as a version control system.
Problem turned out to be that AppCenter does not directly integrate with GitLab. As one of the solutions, a bypass through BitBucket was chosen.
Steps
1. Create an empty repository on BitBucket
I see no need to describe it in more detail π
2. Set up GitLab
We need to push/merge changes to the repository to be uploaded to BitBucket as well. To do this, add a runner (or edit an existing .gitlab-ci.yml file).
First, add commands to the before_scripts section
- git config --global user.email "user@email"
- git config --global user.name "username"
Then add the following command to the required stage:
- git push --mirror https://username:[email protected]/username/projectname.git
In my case, this is the file
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.git
We run the build, check that our changes/files are on BitBucket.
* as practice has shown, setting up SSH keys is optional. But, just in case, I will give the connection setup algorithm through SSH below
Connecting via SSH
First you need to generate an SSH key. Many articles have been written about this. For an example, you can see
The generated keys look something like this:
Next The secret key needs to be added as a variable on GitLab. To do this, go to Settings > CI / CD > Enviroment Variables. We add ALL the contents of the file in which you saved the secret key. Let's name the variable SSH_PRIVATE_KEY.
* this file, unlike the public key file, will not have an extension
Great, the next step is to add the public key to BitBucket. To do this, open the repository, go to Settings > Access Keys.
Here we make Add Key and paste the contents of the file with the public key (file with the .pub extension).
The next step is to use the keys in gitlab-runner. Use these commands, but replace the asterisks with your own 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 [email protected]
mirror:
stage: mirror
script:
- git push --mirror https://****:****@bitbucket.org/*****/*****.git
3. Set up AppCenter
We create a new application on AppCenter.
Specify language/platform
Next, go to the Build section of the newly created application. Select BitBucket there and the repository created in step 1.
Great, now you need to configure the build. To do this, find the gear icon
In principle, everything is intuitively clear there. Select a project and configuration. If necessary, enable the launch of tests after the build. They will start automatically.
Basically, that's all. It sounds easy, but, of course, everything will not go smoothly. Therefore, I will describe some of the errors that I encountered while working:
'ssh-keygen' is not recognized as an internal or external command.
Occurs because the path to ssh-keygen.exe is not added to the environment variables.
There are two options: add C:Program FilesGitusrbin to the Enviroment Variables (will apply after rebooting the machine), or run the console from this directory.
AppCenter connected to the wrong BitBucket account?
To solve the problem, you need to unlink your BitBucket account from AppCenter. We go to the wrong BitBucket account, go to the user profile.
Next go to Settings > Access Management > OAuth
Click Revoke to unlink your account.
After that, you need to log in under the desired BitBucket account
* As a last resort, clear your browser cache.
Now let's go to AppCenter. go to the Build section, click Disconnect BitBucket account
When the old account is unlinked, we link the AppCenter again. Now to the desired account.
'eval' is not recognized as an internal or external command
Use instead of command
- eval $(ssh-agent -s)
Team:
- ssh-agent
In some cases, you will either have to specify the full path to C:\Program Files\Gitusrbinssh-agent.exe, or add this path to the system variables on the machine where runner is running
AppCenter Build is trying to run a build for a project from an outdated bitBucket repository
In my case, the problem arose due to the fact that I worked with several accounts. Decided to clear the cache.
Source: habr.com