Generate a ssh key pair.
Add the private key to the project’s secret variable with a key, “SSH_PRIVATE_KEY.”
Write the yml file as below. 1)https://docs.gitlab.com/ce/ci/ssh_keys/README.html#ssh-keys-when-using-the-docker-executor2)https://gitlab.com/gitlab-org/gitlab-ce/issues/4194
# This file is a template, and might need editing before it works on your project.
# This template uses the java:8 docker image because there isn't any
# official Gradle image at this moment
# This is the Gradle build system for JVM applications
# Make the gradle wrapper executable. This essentially downloads a copy of
# Gradle to build the project with.
# It is expected that any modern gradle project has a wrapper
# Install ssh-agent if not already installed, it is required by Docker.
# (change apt-get to yum if you use a CentOS-based image)
#- 'which ssh-agent || ( yum update -y && yum install openssh-client -y )'
- yum -y install git gunzip openssh-client
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- chmod +x gradlew
- mkdir -p temp
- git clone email@example.com:x-droid/xdroid-libslave.git temp/xdroid-libslave
- sed -i "s/File('\.\./File('temp/g" settings.gradle
# We redirect the gradle user home using -g so that it caches the
# wrapper and dependencies.
# Unfortunately it also caches the build output so
# cleaning removes reminants of any cached builds.
# The assemble task actually builds the project.
# If it fails here, the tests can't run.
- ./gradlew -g /cache/.gradle clean assemble
# Use the generated build output to run the tests.
- ./gradlew -g /cache/.gradle check
References [ + ]