[iOS] Fastlane을 활용한 TestFlight 업로드 자동화 설정 및 오류 해결

pola·2025년 3월 7일

Company

목록 보기
6/7

매번 아카이브하고 앱스토어에 올리는 과정이 번거롭기 시작..
그래서 Fastlane을 활용하면 빌드 및 배포 프로세스를 자동화하기로 함
이번 글에서 Fastlane을 이용해 TestFlight에 앱을 업로드하는 방법과, 발생할 수 있는 오류 및 해결 방법을 정리

1. Fastlane 설치 및 초기화

brew install fastlane

그 후, 프로젝트 디렉터리에서 fastlane init을 실행

cd 프로젝트_경로
fastlane init

이 과정이 끝나면 fastlane 폴더가 생성되고, 내부에 Fastfile을 수정하여 필요한 설정을 추가할 수 있음

2. Fastfile 설정

Fastfile에서 beta라는 lane을 만들어 TestFlight 업로드를 자동화
순차적으로 앱을 빌드하고 테스트플라잇에 업로드한다음 슬랙으로 메세지를 보냄

default_platform(:ios)

platform :ios do
  desc "Build app and upload to TestFlight"
  lane :beta do |options|
    increment_build_number(build_number: latest_testflight_build_number + 1) # 빌드 번호 증가
    if options[:version]
      increment_version_number(version_number: options[:version]) # 버전 번호 증가
    end

    build_app(scheme: "appName") # 앱 빌드
    upload_to_testflight(distribute_external: options[:test]) # TestFlight 업로드 (true: 외부 테스트, false: 내부 테스트)

    send_slack(message: "Build app and upload to TestFlight")
  end

  lane :send_slack do |options|
    version = get_version_number(
      xcodeproj: "appName.xcodeproj",
      target: "appName"
    )
    build = get_build_number

    slack(
      message: options[:message],
      channel: "@channelName",
      slack_url: "url",
      default_payloads: [:lane, :test_result],
      payload: {
        "version": "#{version} (#{build})"
      }
    )
  end
end

3. TestFlight 업로드 실행

아래 명령어(예시)를 실행하여 TestFlight에 업로드할 수 있음

fastlane beta version:1.0.1 test:false

그러나 실행 도중 아래와 같은 오류 발생

[14:25:59]: Error uploading '/var/folders/~.ipa'.
[14:25:59]: Unable to upload archive. Failed to get authorization for username 'email' and password. (
[14:25:59]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure.
[14:25:59]: Could not download/upload from App Store Connect!

이는 Apple의 2단계 인증이 활성화된 경우 발생하는 문제로, 앱 암호(App-Specific Password)를 사용해야 함

4. 환경 변수 설정 및 앱 암호 생성

1) .env 파일 생성 및 설정

fastlane 폴더 내부에 .env 파일을 생성하고 아래 내용을 추가

vim .env
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD="앱 암호"
APP_IDENTIFIER="com.example.app"
APPLE_ID="email@example.com"

2) 앱 암호 생성 방법

Apple ID 계정에서 앱 암호(App-Specific Password) 를 생성해야 합니다.

  1. Apple ID 계정 페이지에 로그인

  2. “로그인 및 보안” 섹션으로 이동

  3. “앱 암호” 클릭

  4. 암호 이름 입력 후 생성

  5. 생성된 암호를 .env 파일의 FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD 값으로 입력

.env파일은 gitignore에 설정해서 개인 암호를 안올리도록 해야함..

3) Appfile 설정

fastlane/Appfile에서 환경 변수를 불러오도록 설정

app_identifier(ENV["APP_IDENTIFIER"]) # The bundle identifier of your app
apple_id(ENV["APPLE_ID"]) # Your Apple email address

5. 최종 실행

환경 변수를 올바르게 설정한 후, 다시 TestFlight 업로드 명령어를 실행하면 정상적으로 업로드 가능

fastlane beta version:1.0.1 test:false

근데 외부테스트, 내부테스트 설정해도 적용이 안되네.........

profile
pola

0개의 댓글