Install Jenkins and Bonobo Git Server under Windows to build Android applications
- Tutorial
Good day. Having no time to delve into Linux Faced with information gaps while searching the network for installation and configuration instructions for the Windows OS of the Jenkins continuous build server for Android, Git server and their integration, I decided to share information about what I got.
You can install JDK, Git for Windows and Android SDK Tools from the very beginning with default settings.
A simple and easy git server under itself requires the installation of IIS and ASP.MVC that includes MS SQL Server Express 2008
Nothing unusual here, add the Web Server (IIS) role:
The main thing in the following form is not to miss adding ASP.NET 4.5 to Feature:
Run the distribution:
Along the way, MS SQL Server 2008 Express will be installed and we will be asked a password for the US sa. I hope without need it will no longer be needed:
After installing MVC, you need to go through the new settings for server roles (not features, but earlier) and add support for ASP.NET4.5 to the web server. Prior to installing ASP.NET MVC 4, this subsection (Application Development) was not in IIS components!
That's it, now you can proceed to directly deploying a git server. Unzip the contents of the distribution package into the wwwroot of the IIS server and give the rights of the IIS_IUSERS KM to modify the App_Data directory:
Launch IIS Manager and convert to BonoboGitServer application:
If everything went as it should on the right in IIS Manager in Action, click Browse: *: 80 (http) and get (if you did not change the name and port) to localhost / BonoboGitServer:
Login and password for the first login admin / admin. The server does not have many settings (in any case, via the web interface), for example, you can change the interface language:
and create new users like developer and jenkins. Under the first, we will work on our own, the second is needed by the future assembly server.
We will create a new repository and give rights to it to the developer and the assembler (there are no jenkins KMs on the screen, but it should be there if you do everything in order ...)
An example repository page with the coveted .git address. Because I went to the server from a browser on the same machine in the address localhost appears in me, but you may have a normal DNS server name or IP.
You can create a project in Android Studio to specify the address of our repository as a remote branch. I’ll skip all this local part.
Jenkins is installed from msi and doesn’t ask much about anything, at the end of the installation a page with the address where we need to copy the initialAdminPassword from the file and paste the password is automatically opened:
In the future, the password UZ admin can also be changed.
It's time to install the necessary plugins and configure the server. Go to Manage Jenkins - Manage Plugins - Avaliable and note:
After restarting Jenkins, go to the Manage Jenkins - Configure System section and set the path to the Android SDK in two places:
And at the very bottom of the same page in the Android SDK root:
If this parameter did not appear to be something wrong with the Android Emulator Plugin, maybe it just did not install.
Next, go to the Manage Jenkins - Global Tool Configuration configuration page to check and, if necessary, specify the path to the components:
Everything seems to be?
In the main Jenkins side menu, click New Item, come up with the name of the task with the type “Freestyle project” and click ok, we get into the task configuration. Do not forget to check the Discard old builds checkbox, otherwise our server will soon be filled with successful builds of all versions:
In the Source Code Management section, specify the URL of the git repository of our project. Looking ahead, we do not start and do not substitute any credentials for accessing the repository:
We will collect the master branch. You can also configure automatic assembly, in particular, polling the repository every minute and starting the assembly if new commits are detected. We mark Poll SCM and write * * * * *:
In the build section, click Add build step and configure the Gradle assembly. The gradle version should be accessible that we specified in Global Tools Configurations. We write a simple Task - “clean build”. These are the tasks available to us in gradlew.bat tasks at the root of the project. You can call here other tasks of the collector, including with the keys.
We also add one Post-build Action - we will save our APK-schniki - Android applications. So we write:
We save the assembly and start it up and see something like this, hang for 10 minutes and cannot reach the repository:
We are not authorized in the git repository! Adding a Login / Password pair to the Jenkins repository (where we left -none- in Source Code Management) did not work, no matter how I tried. We must try to look for other ways.
The command line is launched on behalf of the KM session, Jenkins on behalf of System and does not know anything about it, it seems that the Credential Manager repository will not happen either. Those. this will not help:
An additional search on the network gave some tips:
To do this, we need PsExec.exe from the PsTools utility set . With it, we can run cmd.exe from under System. Run cmd.exe with elevated permissions and execute:
In the new console, all you need to do is knock on the repository we need, for example, try to clone it on the command line. credentials will be requested:
With the help of which Jenkins will be able to access this repository. This is the same KM that we created when setting up Bonobo Git Server along with the developer. If in the future you need to change these credentials, you will have to go through the procedure again.
It may happen that in the SDK any modules are missing and the assembly console issue messages of this nature:
In this case, you need to run SDK Manager with elevated rights and install the missing components:
Everything, after all the shamanism, the assembly was successful!
You can breed a team of Android developers.
PS You can automate the process even more, using the appropriate plug-in, set up automatic publication of apk's in the Google Play Store, but I’ll write about this another time if there are any difficulties.
Distributions
- The OS will be Windows Server 2012 R2 Standard x64
- Jenkins for Windows is in a separate msi
- Bonobo git server
- Jdk
- ASP.NET MVC 4
- Android SDK tools at the bottom of the page, not the environment but only the SDK
- Git for windows x64
Last preparations
You can install JDK, Git for Windows and Android SDK Tools from the very beginning with default settings.
Bonobo git server
A simple and easy git server under itself requires the installation of IIS and ASP.MVC that includes MS SQL Server Express 2008
IIS Server
Nothing unusual here, add the Web Server (IIS) role:
IIS
The main thing in the following form is not to miss adding ASP.NET 4.5 to Feature:
Feature
ASP.NET MVC4
Run the distribution:
ASP.NET MVC4 Install
Along the way, MS SQL Server 2008 Express will be installed and we will be asked a password for the US sa. I hope without need it will no longer be needed:
MS SQL Server installation
After installing MVC, you need to go through the new settings for server roles (not features, but earlier) and add support for ASP.NET4.5 to the web server. Prior to installing ASP.NET MVC 4, this subsection (Application Development) was not in IIS components!
Server Roles - IIS - Web Server - Application Development - ASP.NET 4.5
Bonobo git server
That's it, now you can proceed to directly deploying a git server. Unzip the contents of the distribution package into the wwwroot of the IIS server and give the rights of the IIS_IUSERS KM to modify the App_Data directory:
IIS wwwroot and IZ_IUSERS KM rights to the App_Data directory
Launch IIS Manager and convert to BonoboGitServer application:
IIS Manager Convert to Application
If everything went as it should on the right in IIS Manager in Action, click Browse: *: 80 (http) and get (if you did not change the name and port) to localhost / BonoboGitServer:
Bonobo Git Server login page
Login and password for the first login admin / admin. The server does not have many settings (in any case, via the web interface), for example, you can change the interface language:
Bonobo language
and create new users like developer and jenkins. Under the first, we will work on our own, the second is needed by the future assembly server.
New Bonobo Git Server user
We will create a new repository and give rights to it to the developer and the assembler (there are no jenkins KMs on the screen, but it should be there if you do everything in order ...)
New repository
An example repository page with the coveted .git address. Because I went to the server from a browser on the same machine in the address localhost appears in me, but you may have a normal DNS server name or IP.
Repository address
You can create a project in Android Studio to specify the address of our repository as a remote branch. I’ll skip all this local part.
Remote repository available
Jenkins
Jenkins is installed from msi and doesn’t ask much about anything, at the end of the installation a page with the address where we need to copy the initialAdminPassword from the file and paste the password is automatically opened:
Unlock jenkins
In the future, the password UZ admin can also be changed.
It's time to install the necessary plugins and configure the server. Go to Manage Jenkins - Manage Plugins - Avaliable and note:
- JDK Parameter Plugin
- Git plugin
- Android Emulator Plugin
- Gradle plugin
Jenkins plugins
After restarting Jenkins, go to the Manage Jenkins - Configure System section and set the path to the Android SDK in two places:
ANDROID_HOME in Environment variables
And at the very bottom of the same page in the Android SDK root:
Android SDK root
If this parameter did not appear to be something wrong with the Android Emulator Plugin, maybe it just did not install.
Next, go to the Manage Jenkins - Global Tool Configuration configuration page to check and, if necessary, specify the path to the components:
Global tool configuration
Everything is simple with the JDK:
Git can not be touched, if the path variable contains the path to the git executable and it is available on the command line, then Jenkins can use it:
And let Gradle download automatically. In principle, the same trick could be done with the JDK, but when installing the Android SDK it requires the JDK registered in the system, and I did not dig out where Jenkins downloads the JDK.
Git can not be touched, if the path variable contains the path to the git executable and it is available on the command line, then Jenkins can use it:
And let Gradle download automatically. In principle, the same trick could be done with the JDK, but when installing the Android SDK it requires the JDK registered in the system, and I did not dig out where Jenkins downloads the JDK.
Everything seems to be?
Creating a build task
In the main Jenkins side menu, click New Item, come up with the name of the task with the type “Freestyle project” and click ok, we get into the task configuration. Do not forget to check the Discard old builds checkbox, otherwise our server will soon be filled with successful builds of all versions:
General
In the Source Code Management section, specify the URL of the git repository of our project. Looking ahead, we do not start and do not substitute any credentials for accessing the repository:
Source code management
We will collect the master branch. You can also configure automatic assembly, in particular, polling the repository every minute and starting the assembly if new commits are detected. We mark Poll SCM and write * * * * *:
Build triggers
In the build section, click Add build step and configure the Gradle assembly. The gradle version should be accessible that we specified in Global Tools Configurations. We write a simple Task - “clean build”. These are the tasks available to us in gradlew.bat tasks at the root of the project. You can call here other tasks of the collector, including with the keys.
Gradle
We also add one Post-build Action - we will save our APK-schniki - Android applications. So we write:
**\*apk:
Post-build action
Assembly
We save the assembly and start it up and see something like this, hang for 10 minutes and cannot reach the repository:
git.exe fetch --tags --progress http://localhost/Hello.git +refs/heads/*:refs/remotes/origin/*
We are not authorized in the git repository! Adding a Login / Password pair to the Jenkins repository (where we left -none- in Source Code Management) did not work, no matter how I tried. We must try to look for other ways.
The command line is launched on behalf of the KM session, Jenkins on behalf of System and does not know anything about it, it seems that the Credential Manager repository will not happen either. Those. this will not help:
Credential manager
An additional search on the network gave some tips:
- Transferring ssh keys from the US session to the system, which I could not find;
- The second method (git authorization) that worked.
Git authorization
To do this, we need PsExec.exe from the PsTools utility set . With it, we can run cmd.exe from under System. Run cmd.exe with elevated permissions and execute:
PsExec.exe -i -s cmd.exe
In the new console, all you need to do is knock on the repository we need, for example, try to clone it on the command line. credentials will be requested:
Git
With the help of which Jenkins will be able to access this repository. This is the same KM that we created when setting up Bonobo Git Server along with the developer. If in the future you need to change these credentials, you will have to go through the procedure again.
Lack of components and license acceptances for Android SDK components
It may happen that in the SDK any modules are missing and the assembly console issue messages of this nature:
A problem occurred configuring project ':app'. You have not accepted the license agreements of the following SDK components: [Android SDK Platform 24, Android SDK Build-Tools 24.0.1].
In this case, you need to run SDK Manager with elevated rights and install the missing components:
Android SDK Manager
Everything, after all the shamanism, the assembly was successful!
Successful build!
You can breed a team of Android developers.
PS You can automate the process even more, using the appropriate plug-in, set up automatic publication of apk's in the Google Play Store, but I’ll write about this another time if there are any difficulties.