ARCHIVES

태그

신고하기

상단 메뉴 페이지

기본 콘텐츠로 건너뛰기

[CI/CD] Android 새로운 프로젝트에 적용하기 - 2022.07.11

Android 새로운 프로젝트에 적용하기

이 글은, 새로 처음부터 하는것이 아닌,

그동안 CI/CD 구축이 진행된 프로젝트를 종료하고, 

새로운 프로젝트를 추가하는 방식을 간단하게 표현한 것이다.

이미, git, fastlane, jenkins, dropbox, firebase, slack 은 설치가 되서 운영중이다.

2022.07.11


가. Android 새로운 프로젝트에 develop 등록하기.

1. 프로젝트를 git에 등록한다.

2. develop 브랜치를 생성하여 이를 사용한다.

3. 프로젝트 폴더로 이동해서, fastlane 적용, 설치 도중 물어보는 패키지 명을 잘 적어준다.

    fastlane init

4. fastlane plugin 설치 (version, slack, firebase 도우미) - 베타, 운영 빌드에 사용함.

    $ fastlane add_plugin 'fastlane-plugin-versioning_android'
    $ fastlane add_plugin 'fastlane-plugin-slack_upload'
    $ fastlane add_plugin 'fastlane-plugin-firebase_app_distribution'

5. 적용 확인.

$ fastlane test

    [11:02:12]: fastlane.tools finished successfully 🎉

6. '.gitignore' 파일에 불필요한 정보 업로드 되지 않도록 추가. - jenkins 충돌방지

Gemfile.lock
/fastlane/README.md
/fastlane/report.xml

=====

개발버전 배포의 경우 빌드넘버와 버전넘버를 올리지 않고,
받을 수 있는 서버에 지속적으로 덮어씌우는 방식으로 배포한다. ios 혼합배포가 가능한 dropbox 사용.
배포 페이지는 jenkins 설치 서버에 별도의 웹 서비스를 사용한다.

=====

1. dropbox 다운로드 경로 설정

2. 드랍박스에 파일을 올리고 아래와 같은 경로가 생기면, 바꿔준다.

    원본: https://www.dropbox.com/s/6s3yjd493d8rt0t/앱이름-debug.apk?dl=0
    변경: https://dl.dropboxusercontent.com/s/6s3yjd493d8rt0t/앱이름-debug.apk

    이 경로를 웹서비스에 다운로드 할 수 있도록 한다. (주소자체로 설치 가능)

=====

개발버전 fastlane 작성, /fastlane/Fastfile 을 수정한다.

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#

default_platform(:android)

platform :android do

before_all do
# 슬랙 URL
ENV["SLACK_URL"] = "https://hooks.slack.com/services/T02DGE33FD0/B02MBJ0T2R5/xxxxxxxxxxxxxxxxxxxxxxxx"
ENV["output_name"] = "eswms"
ENV["SLACK_BOT_TOKEN"] = "xoxb-2458479117442-2734158993558-xxxxxxxxxxxxxxxxxxxxxx"
ENV["SLACK_BOT_CHANEL"] = "배포"
end

# 빌드 시작시간
build_date_time = "#{Time.new.strftime("%m-%d %H:%M")}"

######################### PUBLIC LANES #########################

desc "개발 버전은 슬랙으로 배포한다."
lane :dev do
# 시작 알림
slack_send(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!", success: true)
# 빌드
gradle(task: "clean assemble", build_type: "Debug")
# 파일이동 및 변경
sh "mv ../app/build/outputs/apk/debug/app-debug.apk #{dropbox_directory}/#{ENV["output_name"]}-debug.apk"
# 종료 파일 알림
slack_dropbox(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드완료!", success: true)
# 순서 맨 마지막 이어야 함. 아이폰과 동일하게 드랍박스 배포를 한다.
hk_make_download_html(vn: android_get_version_name, bn: android_get_version_code)
end

desc "웹 후킹을 사용해 슬렉에 메세지를 보낸다."
private_lane :slack_send do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
default_payloads: [:git_branch, :last_git_commit_message]
)
end

desc "슬렉, 드랍박스 링크를 제공한다."
private_lane :slack_dropbox do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
attachment_properties: {
actions: [{
type: "button",
text: "#{ENV["output_name"]}-debug.apk",
url: "#{dropbox_download_link}"
}]
},
default_payloads: []
)
end

# 날짜가 들어간 드랍박스 페이지 생성
private_lane :hk_make_download_html do |options|
Dir.chdir localhost_directory
out_file = File.open("and.html", "w") { |file| file.write("#{download_html_head} #{build_date_time} ESWMS AND #{options[:vn]}(#{options[:bn]})#{download_html_body}") }
end

end

def dropbox_download_link
"http://xx.xx.xx.xx/eswms/ios.html"
end

def dropbox_directory
"/Users/jaehwanchoo/Dropbox/ESWMS"
end

def localhost_directory
"/Library/WebServer/Documents/eswms"
end

def download_html_head
"
<!doctype html>
<html>
<head>
<meta charset='utf-8'/>
<meta http-equiv='Cache-Control' content='no-cache'/>
<meta http-equiv='Expires' content='-1'/>
<meta http-equiv='Pragma' content='no-cache'/>
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'/>
<link rel='stylesheet' href=''/>
</head>
<body>
<h4>"
end

def download_html_body
" </h4>
<a href='https://dl.dropboxusercontent.com/s/xxxxxxxxxxx/eswms-debug.apk'>안드로이드 DEV_APP 설치</a>
</body>
</html>
"
end

==============

슬랙 프로젝트를 생성하고 후크, 봇을 만들어 보자.

1. 슬랙 "프로젝트"를 만들고, "배포" 채널을 만든다.

2. 아래의 경로에 들어가 보자.

    https://api.slack.com/apps

3. "Create New App" 클릭, 봇을 하나 만든다. "ES업로더"와 같은 이름으로 만든다.

4. 퍼미션 -> chat::write, file::write 권한을 준다.



5. 슬랙으로 와서, 내가 만듯 봇 추가. 또는 apps 채널에서 추가


6. manifast로 생성해서 "설치할 봇 사용자가 없습니다" 라고 에러가 뜨는경우
    봇 디스플레이 이름이 없어서 이다.

Features -> App Home -> App Display Name 설정 해준다.

앱을 추가하면 나오는 봇 토큰을 잘 저장한다.

7. Incoming WebHooks 앱 설치 한다.

    https://my.slack.com/services/new/incoming-webhook/

    경로가 나오면 SLACK_URL 위치에 잘 저장 한다.

8. 적용 확인.

$ fastlane dev





==============

이제 젠킨스를 통한 빌드 체계를 만든다.

1. 젠킨스 프리스타일 프로젝트를 만든다. 어차피 할거닌까 3개 만들도록 한다.

    ESWMS_AND_1_DEV

    ESWMS_AND_2_BETA

    ESWMS_AND_3_PROD

2. 깃 연결, 및  환경 설정

    - 깃 주소 준비

    - 깃 토큰 준비

    - 빌드트리거 설정 [JENKINS_URL]/buildWithParameters?token=start

3. 배포 버튼을 사용한 빌드 확인






==============

슬랙 커맨드 명렁어로 빌드를 실행 해보기

커맨드 명령어로 하려면 젠킨스가 https 외부 서버가 되어야 한다.

https의 경우 구축도 까다롭고 계속 관리(인증서, 비용) 해야 하기 때문에,

synology nas  또는  ngrok 를 사용한 https 구축을 진행했다. (구축을 했다는 전제하에 진행)

1. 아래의 경로에 들어가 보자.

    https://api.slack.com/apps

2. Slash Commends 메뉴로 이동


3. 젠킨스에 빌드 트리거를 설치 해두어야 한다. [JENKINS_URL]/buildWithParameters?token=start

4. 경로를 설정하고, 내용을 적당히 채우고, 저장한다.

5. 빌드 실행


여기까지 개발버전 완료


나. Android 새로운 프로젝트에 betaTest 등록하기.

베타테스트는 firebase app distribution 을 사용해서 릴리즈 배포를 진행한다.

파이어베이스를 어느정도 사용해보고 이해한 뒤 이를 진행 가능하다.

안드로이드 프로젝트 패키지 명을 가진 프로젝트 생성, 프로젝트에 포함.

어차피 크래쉬리스틱과 아날리스틱을 사용하기 위해서 등록 해야 한다.(여기까지 기본적용)


1. firebase 프로젝트를 만들고, 테스터를 추가한다.

2. FIREBASE_APP_ID 구하기

    프로젝트 설정 -> Android 앱 SDK 설정 및 구성 -> 앱ID

    1:1096706045751:android:xxxxxxxxxxxxxxxxxxxx

3. FIREBASE_APP_TOKEN 구하기

    Firebase CLI 를 통한 배포는 PC에 Firebase Tool 이 설치되어 있어야합니다.

    이후 로그인을 수행합니다.

$ firebase login:ci

    토큰이 나오면 이를 사용 합니다.

    로그인 한 이후 다시 명령어를 입력해보시면 현재 로그인되어있는 계정의 정보가 출력됩니다.

$ firebase projects:list

4. 이제 fastlane beta를 구축 합니다.

    최초 fastlane을 설치 할 때, firebase 플러그인을 설치 해두어야 합니다.

    $ fastlane add_plugin 'fastlane-plugin-firebase_app_distribution'

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#

default_platform(:android)

platform :android do

before_all do
# 슬랙 URL
ENV["SLACK_URL"] = "https://hooks.slack.com/services/T02DGE33FD0/B02MBJ0T2R5/xxxxxxxxxx"
ENV["output_name"] = "eswms"
ENV["SLACK_BOT_TOKEN"] = "xoxb-2458479117442-2734158993558-xxxxxxxxxxxxxxxxxxxxxx"
ENV["SLACK_BOT_CHANEL"] = "배포"
# 파이어베이스 토큰, 아이디 - (메일그룹 groups: "hk-tester" 필요)
ENV["FIREBASE_APP_ID"] = "1:1096706045751:android:xxxxxxxxxxxxxxx"
ENV["FIREBASE_APP_TOKEN"] = "1//0ePFaiiVwUrhuCgYIARAAGA4SNwF-xxxxxxxxxxxxxxxxxxxxxxxxxx"
end

# 빌드 시작시간
build_date_time = "#{Time.new.strftime("%m-%d %H:%M")}"

######################### PUBLIC LANES #########################

desc "개발 버전은 슬랙으로 배포한다."
lane :dev do
# 시작 알림
slack_send(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!", success: true)
# 빌드
gradle(task: "clean assemble", build_type: "Debug")
# 파일이동 및 변경
sh "mv ../app/build/outputs/apk/debug/app-debug.apk #{dropbox_directory}/#{ENV["output_name"]}-debug.apk"
# 종료 파일 알림
slack_dropbox(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드완료!", success: true)
# 순서 맨 마지막 이어야 함. 아이폰과 동일하게 드랍박스 배포를 한다.
hk_make_download_html(vn: android_get_version_name, bn: android_get_version_code)
end


desc "베타버전은 firebase_app_distribution 배포 한다."
lane :beta do |options|
# 버전 코드 증가
increment_version_code
# 버전 네임 고정
fixed_version_name(bump_fix: options[:bump_fix])
# 깃 푸시
# hk_push_to_git_remote(brench_name: options[:brench_name])
# 시작 알림
slack_send(message: "#{build_date_time} 👽And 베타👽 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!!", success: true)
# 빌드 (signingConfigs 릴리즈에 필요한 정보는 설정 되어있다.)
gradle(task: "clean assemble", build_type: "Release")
# 테스트 서버 업로드
hk_firebase_app_distribution
# 종료 테스트 링크 제공
slack_button(message: "#{build_date_time} 👽And 베타👽 #{android_get_version_name}(#{android_get_version_code}) 빌드완료!!", success: true)
end


######################### PRIVATE LANES #########################
desc "웹 후킹을 사용해 슬렉에 메세지를 보낸다."
private_lane :slack_send do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
default_payloads: [:git_branch, :last_git_commit_message]
)
end

desc "슬렉, 드랍박스 링크를 제공한다."
private_lane :slack_dropbox do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
attachment_properties: {
actions: [{
type: "button",
text: "#{ENV["output_name"]}-debug.apk",
url: "#{dropbox_download_link}"
}]
},
default_payloads: []
)
end

desc "날짜가 들어간 드랍박스 페이지 생성"
private_lane :hk_make_download_html do |options|
Dir.chdir localhost_directory
out_file = File.open("and.html", "w") { |file| file.write("#{download_html_head} #{build_date_time} ESWMS AND #{options[:vn]}(#{options[:bn]})#{download_html_body}") }
end

desc "친절한 슬렉씨, 다운로드 링크를 제공한다."
private_lane :slack_button do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
attachment_properties: {
actions: [{
type: "button",
text: "android 베타 설치하기",
url: "https://appdistribution.firebase.google.com/testerapps"
}]
},
default_payloads: []
)
end

end

######################### BETA, PRODUCTION #########################
# 버전 코드 증가
def increment_version_code
path = '../app/build.gradle'
re = /versionCode\s+(\d+)/

s = File.read(path)
versionCode = s[re, 1].to_i
s[re, 1] = (versionCode + 1).to_s

f = File.new(path, 'w')
f.write(s)
f.close
end

# 버전 이름 고정
def fixed_version_name(bump_fix: nil)
path = '../app/build.gradle'
re = /versionName\s+("\d+.\d+.\d+")/

if bump_fix.nil?
major = 0
minor = 0
patch = 1
else
fixName = bump_fix.split('.')

major = fixName[0].to_i
minor = fixName[1].to_i
patch = fixName[2].to_i
end

s = File.read(path)
s[re, 1] = "\"#{major}.#{minor}.#{patch}\""

f = File.new(path, 'w')
f.write(s)
f.close
end

# 깃 푸시
def hk_push_to_git_remote(brench_name: nil)
remoteBranch = brench_name
if brench_name == nil
remoteBranch = "develop"
end

sh "git commit -am \"build: auto increment version #{android_get_version_name} (#{android_get_version_code})\""
push_to_git_remote(
remote: "origin",
local_branch: "HEAD",
remote_branch: brench_name)
end

# 파이어베이스 배포
def hk_firebase_app_distribution
firebase_app_distribution(
app: ENV['FIREBASE_APP_ID'],
firebase_cli_token: ENV['FIREBASE_APP_TOKEN'],
groups: "hk-tester",
debug: true
)
end

######################### BETA, PRODUCTION #########################

######################### DEV HTTP #########################
def dropbox_download_link
"http://xxxxxx/eswms/ios.html"
end

def dropbox_directory
"/Users/jaehwanchoo/Dropbox/ESWMS"
end

def localhost_directory
"/Library/WebServer/Documents/eswms"
end

def download_html_head
"
<!doctype html>
<html>
<head>
<meta charset='utf-8'/>
<meta http-equiv='Cache-Control' content='no-cache'/>
<meta http-equiv='Expires' content='-1'/>
<meta http-equiv='Pragma' content='no-cache'/>
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'/>
<link rel='stylesheet' href=''/>
</head>
<body>
<h4>"
end

def download_html_body
" </h4>
<a href='https://dl.dropboxusercontent.com/s/xxxx/eswms-debug.apk'>안드로이드 DEV_APP 설치</a>
</body>
</html>
"
end
######################### DEV HTTP #########################

5. 적용 확인.

$ fastlane beta brench_name:"betaTest" bump_fix:1.0.0

==============

이제 젠킨스를 통한 빌드 체계를 만든다.

1. 젠킨스 프리스타일 프로젝트 만들도록 한다. (위에서 만들었으면 설정으로 이동)

    ESWMS_AND_2_BETA

2. 깃 연결, 및  환경 설정

    - 깃 주소 준비

    - 깃 토큰 준비

    - 빌드트리거 설정 [JENKINS_URL]/buildWithParameters?token=start

3. 배포 버튼을 사용한 빌드 확인

==============

==============

슬랙 커맨드 명렁어로 빌드를 실행 해보기

    https://api.slack.com/apps

1. Slash Commends 메뉴로 이동

    Dev와 동일하게 커맨드 명령어를 넣는다.

완료

==============


다. Android 새로운 프로젝트에 Production 등록.

마지막 프로덕션 등록 하기다.

1. fastlane production 구축 합니다.

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#

default_platform(:android)

platform :android do

before_all do
# 슬랙 URL
ENV["SLACK_URL"] = "https://hooks.slack.com/services/T02DGE33FD0/B02MBJ0T2R5/xxxxxxxxxx"
ENV["output_name"] = "eswms"
ENV["SLACK_BOT_TOKEN"] = "xoxb-2458479117442-2734158993558-xxxxxxxxxxxxxxxxxxxxxx"
ENV["SLACK_BOT_CHANEL"] = "배포"
# 파이어베이스 토큰, 아이디 - (메일그룹 groups: "hk-tester" 필요)
ENV["FIREBASE_APP_ID"] = "1:1096706045751:android:xxxxxxxxxxxxxxx"
ENV["FIREBASE_APP_TOKEN"] = "1//0ePFaiiVwUrhuCgYIARAAGA4SNwF-xxxxxxxxxxxxxxxxxxxxxxxxxx"
end

# 빌드 시작시간
build_date_time = "#{Time.new.strftime("%m-%d %H:%M")}"

######################### PUBLIC LANES #########################

desc "개발 버전은 슬랙으로 배포한다."
lane :dev do
# 시작 알림
slack_send(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!", success: true)
# 빌드
gradle(task: "clean assemble", build_type: "Debug")
# 파일이동 및 변경
sh "mv ../app/build/outputs/apk/debug/app-debug.apk #{dropbox_directory}/#{ENV["output_name"]}-debug.apk"
# 종료 파일 알림
slack_dropbox(message: "#{build_date_time} 🤖AND 개발🤖 #{android_get_version_name}(#{android_get_version_code}) 빌드완료!", success: true)
# 순서 맨 마지막 이어야 함. 아이폰과 동일하게 드랍박스 배포를 한다.
hk_make_download_html(vn: android_get_version_name, bn: android_get_version_code)
end


desc "베타버전은 firebase_app_distribution 배포 한다."
lane :beta do |options|
# 버전 코드 증가
increment_version_code
# 버전 네임 고정
fixed_version_name(bump_fix: options[:bump_fix])
# 깃 푸시 - 진짜 배포시에 커밋
# hk_push_to_git_remote(brench_name: options[:brench_name])
# 시작 알림
slack_send(message: "#{build_date_time} 👽And 베타👽 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!!", success: true)
# 빌드 (signingConfigs 릴리즈에 필요한 정보는 설정 되어있다.)
gradle(task: "clean assemble", build_type: "Release")
# 테스트 서버 업로드
hk_firebase_app_distribution
# 종료 테스트 링크 제공
slack_button(message: "#{build_date_time} 👽And 베타👽 #{android_get_version_name}(#{android_get_version_code}) 빌드완료!!", success: true)
end


desc "운영 배포한다. 엔터프라이즈 버전이라 메일로 보낸다."
lane :prod do |options|
# 버전 코드 증가
increment_version_code
# 버전 네임 증가
increment_version_name(bump_type: options[:bump_type], bump_fix: options[:bump_fix])
# 깃 푸시 - 진짜 배포시에 커밋
# hk_push_to_git_remote_release(brench_name: options[:brench_name])

# 시작 알림
slack_send(message: "#{build_date_time} 🎃AND 운영🎃 #{android_get_version_name}(#{android_get_version_code}) 빌드시작!", success: true)
# 빌드 메일 테스트 # 일단 디버그
gradle(task: "clean assemble", build_type: "Release")
# 파일이동 및 변경 # 일단 디버그
sh "mv ../app/build/outputs/apk/release/app-release.apk ../app/build/#{ENV["output_name"]}_#{android_get_version_name}.apk"
# 종료 시작 알림
# 파일 업로드
my_slack_upload(comment: "#{build_date_time} 🎃AND 운영🎃 파일다운" ,vn: android_get_version_name)
end

######################### PRIVATE LANES #########################
desc "웹 후킹을 사용해 슬렉에 메세지를 보낸다."
private_lane :slack_send do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
default_payloads: [:git_branch, :last_git_commit_message]
)
end

desc "슬렉, 드랍박스 링크를 제공한다."
private_lane :slack_dropbox do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
attachment_properties: {
actions: [{
type: "button",
text: "#{ENV["output_name"]}-debug.apk",
url: "#{dropbox_download_link}"
}]
},
default_payloads: []
)
end

desc "날짜가 들어간 드랍박스 페이지 생성"
private_lane :hk_make_download_html do |options|
Dir.chdir localhost_directory
out_file = File.open("and.html", "w") { |file| file.write("#{download_html_head} #{build_date_time} ESWMS AND #{options[:vn]}(#{options[:bn]})#{download_html_body}") }
end

# 베타 배포에서 사용
desc "친절한 슬렉씨, 다운로드 링크를 제공한다."
private_lane :slack_button do |options|
slack(
message: options[:message],
slack_url: ENV['SLACK_URL'],
attachment_properties: {
actions: [{
type: "button",
text: "android 베타 설치하기",
url: "https://appdistribution.firebase.google.com/testerapps"
}]
},
default_payloads: []
)
end

# 운영 배포에서 사용
desc "슬랙봇을 이용해 슬랙 채널에 파일을 업로드 한다."
private_lane :my_slack_upload do |options|
# Upload to slack
slack_upload(
slack_api_token: ENV['SLACK_BOT_TOKEN'],
title: "#{ENV["output_name"]}_#{options[:vn]}.apk",
channel: ENV['SLACK_BOT_CHANEL'],
file_path: "./app/build/#{ENV["output_name"]}_#{options[:vn]}.apk",
initial_comment: options[:comment]
)
end

end

######################### BETA #########################
# 버전 코드 증가
def increment_version_code
path = '../app/build.gradle'
re = /versionCode\s+(\d+)/

s = File.read(path)
versionCode = s[re, 1].to_i
s[re, 1] = (versionCode + 1).to_s

f = File.new(path, 'w')
f.write(s)
f.close
end

# 버전 이름 고정
def fixed_version_name(bump_fix: nil)
path = '../app/build.gradle'
re = /versionName\s+("\d+.\d+.\d+")/

if bump_fix.nil?
major = 0
minor = 0
patch = 1
else
fixName = bump_fix.split('.')

major = fixName[0].to_i
minor = fixName[1].to_i
patch = fixName[2].to_i
end

s = File.read(path)
s[re, 1] = "\"#{major}.#{minor}.#{patch}\""

f = File.new(path, 'w')
f.write(s)
f.close
end

# 깃 푸시
def hk_push_to_git_remote(brench_name: nil)
remoteBranch = brench_name
if brench_name == nil
remoteBranch = "develop"
end

sh "git commit -am \"build: auto increment version #{android_get_version_name} (#{android_get_version_code})\""
push_to_git_remote(
remote: "origin",
local_branch: "HEAD",
remote_branch: brench_name)
end

# 파이어베이스 배포
def hk_firebase_app_distribution
firebase_app_distribution(
app: ENV['FIREBASE_APP_ID'],
firebase_cli_token: ENV['FIREBASE_APP_TOKEN'],
groups: "hk-tester",
debug: true
)
end

######################### BETA #########################

######################### PRODUCTION #########################

# 버전 이름, 코드 증가
def increment_version_name(bump_type: "patch", bump_fix: nil)
path = '../app/build.gradle'
re = /versionName\s+("\d+.\d+.\d+")/

s = File.read(path)
versionName = s[re, 1].gsub!('"','').split('.')

major = versionName[0].to_i
minor = versionName[1].to_i
patch = versionName[2].to_i

if bump_fix.nil?
if (bump_type == 'major')
major += 1
minor = 0
patch = 0
elsif (bump_type == 'minor')
minor += 1
patch = 0
elsif (bump_type == 'patch')
patch += 1
end
else
fixName = bump_fix.split('.')

major = fixName[0].to_i
minor = fixName[1].to_i
patch = fixName[2].to_i
end

s[re, 1] = "\"#{major}.#{minor}.#{patch}\""

f = File.new(path, 'w')
f.write(s)
f.close
end

# 깃 푸시
def hk_push_to_git_remote_release(brench_name: nil)
remoteBranch = brench_name
if brench_name == nil
remoteBranch = "develop"
end

sh "git commit -am \"build: auto increment version release #{android_get_version_name} (#{android_get_version_code})\""
add_git_tag(tag: "release/#{android_get_version_name}_#{android_get_version_code}")
push_to_git_remote(
remote: "origin",
local_branch: "HEAD",
remote_branch: brench_name)
end

######################### PRODUCTION #########################



######################### DEV HTTP #########################
def dropbox_download_link
"http://xxxxxxxxxxx/eswms/ios.html"
end

def dropbox_directory
"/Users/jaehwanchoo/Dropbox/ESWMS"
end

def localhost_directory
"/Library/WebServer/Documents/eswms"
end

def download_html_head
"
<!doctype html>
<html>
<head>
<meta charset='utf-8'/>
<meta http-equiv='Cache-Control' content='no-cache'/>
<meta http-equiv='Expires' content='-1'/>
<meta http-equiv='Pragma' content='no-cache'/>
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'/>
<link rel='stylesheet' href=''/>
</head>
<body>
<h4>"
end

def download_html_body
" </h4>
<a href='https://dl.dropboxusercontent.com/s/xxxx/eswms-debug.apk'>안드로이드 DEV_APP 설치</a>
</body>
</html>
"
end
######################### DEV HTTP #########################


==============

이제 젠킨스를 통한 빌드 체계를 만든다.

1. 젠킨스 프리스타일 프로젝트 만들도록 한다. (위에서 만들었으면 설정으로 이동)

    ESWMS_AND_3_PROD

2. 깃 연결, 및  환경 설정

    - 깃 주소 준비

    - 깃 토큰 준비

    - 빌드트리거 설정 [JENKINS_URL]/buildWithParameters?token=start

3. 배포 버튼을 사용한 빌드 확인

==============

==============

슬랙 커맨드 명렁어로 빌드를 실행 해보기

    https://api.slack.com/apps

1. Slash Commends 메뉴로 이동

    Dev와 동일하게 커맨드 명령어를 넣는다.

2. 배포 채널안에 "커스텀 앱" 이 들어 있어야 한다.

    채널 -> 통합 -> 앱추가 -> 커스텀 앱 선택해서 추가.

3. 완료.

==============



댓글