CI 지속적 통합
빌드 -> 테스트 -> 인스펙션 -> 디플로이 -> 피드백 -> 커밋, 정기,릴리즈 빌드
Circle CI 가벼워 도입장벽이 낮고 Saas 환경에서(유사 travis CI, Codeship)
Jenkins 프로젝트 설정 모두 가능 서버 운영 환경 정비

리눅스에 젠킨스 설치
서버 확인
$uname -a 
자바 설치
$sudo apt-get install openjdk-7-jre 
$sudo apt-get install openjdk-7-jdk
$java -version
$javac -version
젠킨스 설치
$wget -q -0 - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
$sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources. list.d/jenkins.list
$sudo apt-get update
$sudo apt-get install jenkins
http://localhost:8080에 접속해서 확인
sudo cat /var/lib/jenkins/secrets/initialAdminPassword 패스워드 복사후 잠금해제

install suggested plugins
계정 생성하고 필요한 권한 설정

안드로이드 환경 구축
젠킨스 사용자로 변경
$sudo su jenkins
$cd ~
안드로이드 sdk 다운로드
$wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
$tar -xvf android-sdk_r24.4.1-linux.tgz
$rm android-sdk_r24.4.1-linux.tgz
필요한 패키지 설치
$android-sdk-linux/tools/android update sdk --no-ui --all --filter "platform-tools"
$android-sdk-linux/tools/android update sdk --no-ui --all --filter "tools"
$android-sdk-linux/tools/android update sdk --no-ui --all --filter "android-23"
$android-sdk-linux/tools/android update sdk --no-ui --all --filter "extra-android-m2repository"
$android-sdk-linux/tools/android update sdk --no-ui --all --filter "sys-img-x86_64-android-23"
빌드 자동화
디버그
git으로 프로젝트 클론 git plugin github plugin 설치
https://localhost:8080/pluginManager/available 플러그인 관리 페이지
깃허브에서 프로젝트 클론(소스코드 관리 -> git -> repository url 지정)
build에서 execute shell 실행 스크립트 입력란에 ./gradlew assembleDebug 입력
결과물 저장 기능으로 다운로드 할 수 있게 한다
Android sdk 경로 Jenkins 관리->시스템 속성->Global properties에서 환경변수 설정
설정 마치고 build now

깃허브 빌드하기
지정한 시간마다 작업 설정 항목 중 빌드 유발에서 Poll SCM 설정
깃허브의 푸시를 트리거로 깃허브 쪽에서 Webhooks 설정에서 Jenkins URL 지정
플러그인O : Jenkins 빌드 유발에서 Github hook trigger for GitScm polling 에 체크
플러그인X : 포스트되는 데이터를 직접 처리해서 빌드

릴리스 빌드 자동
./gradlew assembleRelease
app/sample.keystore
app/signingconfig.properties
storePassword=password
keyAlias=sample
keyPassword=password
릴리즈용 설정
signingConfigs{ release { 
def configFile = file("signingconfig.properties")
def props = new Properties()
props.load(new FileInputStream(configFile))

storeFile file("sample.keystore")
storePassword props.storePassword
keyAlias props.keyAlias
keyPassword props.keyPassword } }
buildTypes{ release{ signingConfig signingConfigs.release } }
암호화된 서명 파일 준비
공개키 만들기
$openssl rand 32 -out key -base64
$cat key
암호화
$openssl enc -e -aes128 -kfile key -in app/signingconfig.properties -out app/signingconfig.properties.aes128
$openssl enc -e -aes128 -kfile key -in app/sample.keystore -out app/sample.keystore.aes128
커밋
$git add app/signingconfig.properties.ae128 app/sample.keystore.aes128
$git commit -m "add signing secure files."
복호화 execute shell
$echo "공개키" > key
$openssl enc -d -aes128 -kfile key -in app/signingconfig.properties.aes128 -out app/signingconfig.properties
$openssl enc -d -aes128 -kfile key -in app/sample.keystore.aes128 -out app/sample.keystore
테스트 자동화 execute shell
./gradlew clean test

코드 커버리지 시각화 플러그인(Jacoco Cobertura)

android emulator plugin 설치 후
빌드환경 설정
run an android emulator during build
run emulator with properties

인스펙션 자동화
android lint (그레이들 이용하면 설정없이 그대로 실행가능 ./gradlew lint
https://wiki.jenkins.io/display/jenkins/android+lint+plugin

findbugs ./gradlew lint findbugs 설정(app/build.gradle)
apply plugin: 'findbugs'
task findbugs(type:FindBugs, dependsOn:assembleDebug)
{ ignoreFailures = true
effort="max"
reportLevel = "medium"
excludeFilter = new File("config/findbugs/filter.xml")
classes = files("build/intermediates/classes/")
source 'src/main'
include '**/*.java'
reports{
xml.enabled = true
html.enabled = false }
classpath=files() }
분석대상제외 지정 filter.xml










그밖의 코드분석도구 Checkstyle PMD

디플로이 자동화
DeployGate 디버그 빌드 deploygate.com

DeployGate 설정(app/build.gradle)
deploygate
{ username="USER_NAME" token="TOKEN"
apks{ release{ sourceFile= file("[release apk file path]") }
debug{ sourceFile= file("[debug apk file path]") } } }
./gradlew uploadDeployGate

구글 플레이 개발자 API
developers.google.com/android-publisher/ 를 이용해 자동화가능

Circle CI
circleci.com
커밋할때마다 빌드 release 브랜치는 릴리즈 빌드 나머지는 디버그
테스트 실행 결과 파일 저장
코드 분석 결과 파일 저장
DeployGate에 Apk업로드

Circle CI 설정(circle.yml)

빌드환경설정
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter 
"android-23,build-tools-23.0.3,extra-android-m2repository,extra-android-support"
실행할 커맨드 설정
test:
override:
-if ["$CIRCLE_BRANCH" = "release" ]; then
./gradlew assembleRelease;
else
./gradlew assembleDebug;
fi
- ./gradlew lint; cp -r app/build/outputs $CIRCLE_ARTIFACTS
- ./gradlew findbugs; cp -r app/build/reports $CIRCLE_ARTIFACTS
apk가 생기면 마지막으로 DeployGate에 업로드
deployment:
test:
branch: /*/
commands:
- ./gradlew uploadDeployGate
블로그 이미지

dev김

안드로이드 개발자로 만 4년이 좀 안되게 근무했었고 그 이상의 공백을 가지고 있다. 다시 현업에 복귀하기 위한 노력의 흔적을 담으려고 한다.

,