AndroidCI

CI Architecture

Setup Environment

Docker

Jenkins

  • Pull the latest Jenkins Docker image

    docker pull jenkins:2.60.3-alpine
  • Run Jenkins

    Run Jenkins container with a mounted jenkins_home volume, all plugins and settings will be persisted.

    docker run -p 8080:8080 -p 50000:50000 -v $(pwd)/jenkins_home:/var/jenkins_home jenkins:2.60.3-alpine
  • Get the initial admin password

    docker cp $(docker ps -aq -f "ancestor=jenkins:2.60.3-alpine" -f "status=running"):/var/jenkins_home/secrets/initialAdminPassword initialAdminPassword && cat initialAdminPassword && rm initialAdminPassword
  • Install Plugins (no need if you use persistent volume)

  • Configure Docker Plugin

    Setup guide (from the official plugin web page) is here.

    Jenkins -> Manage Jenkins -> Configure System -> Cloud -> Add a new cloud -> Docker

    Regarding the Docker Host URI, it should be tcp://<YOUR_DOCKER_HOST_IP_ADDRESS>:2376

    For the sake of workshop, we will use the Docker host on the same machine where the Jenkins container is running. Thus you can use the IP address of your host machine. Or simply use a DNS name host.docker.internal if you're using the latest version of docker-for-mac or docker-for-windows (not yet implemented for Linux).

    And then you'll have to listen to the port:

    # on macOS
    brew install socat
    socat TCP-LISTEN:2376,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock

    Finally, you can click Docker Agent templates... -> Add Docker Template

  • SSH authentication

    Create a new bash session to the Jenkins container

    docker exec -it $(docker ps -aq -f "ancestor=jenkins:2.60.3-alpine" -f "status=running" ) bash

    Generate a new SSH key

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    The keys will be generated here by default:

    /var/jenkins_home/.ssh/id_rsa.pub
    /var/jenkins_home/.ssh/id_rsa

    Copy the content of your id_rsa.pub file and put into the mounted authorized_keys file.

    Add and set a new SSH credential in Jenkins

Android SDK

Project and source code

Docker Image