LoginSignup
2
2

More than 5 years have passed since last update.

Jenkins Pluginに頼らずシェルだけでJobを構築する(AppStore編)

Last updated at Posted at 2016-07-21

概要

Jenkins Pluginを使うとJenkinsのバージョンを上げた時に動作しなくなったり、そもそもGUI設定が面倒だったりで、実はシェルで書いた方が楽じゃん。と思っているのでそうします。
(全く使わないわけではなく、Jenkins2でのお勧めPluginをそのまま入れとくぐらいはやります)
いまどきはfastlaneでビルドしたり、Webサービス使ったりと思います。が、Jenkins + シェルでやります。

シェルで書いておくメリットは、コマンドレベルで何をしているのかが理解できることでしょう。

インストール

jenkins

homebrewで入れてます。

$ brew update
$ brew cask install java
$ brew install jenkins

設定はネットで探せばすぐ出てくるので割愛。

想定運用

前提として、バージョン(CFBundleShortVersionString)を上げたら、ビルド番号(CFBundleVersion)を、0 でpushしておきます。
Jobを起動したら、ビルド番号を+1して、ipaファイルとdSYMファイルの作成します。
成功したら、自動で+1されたビルド番号をcommitして、tagを作成してpushします。

あとは手動でApplication LoaderでAppStoreにアップロードします。

#Job

JenkinsのGUI設定

  • ソースコード管理でGitの設定をします。
  • ビルドでシェルの実行を記述します。プロビジョニングプロファイルは端末追加するたびに変わるのでここに記述します。
#!/bin/bash -l

PROVISIONING_PROFILE="XXXXXXX-XXXXXXX"

export WORKSPACE
sh ${WORKSPACE}/jenkins/buildForAppStore.sh ${PROVISIONING_PROFILE}

sh ${WORKSPACE}/jenkins/createTag.sh

  • ビルド後の処理で成果物を保存をします。
    build/**/*.ipa,build/**/*.dSYM.zip

Jenkins外のシェル

ipa作成処理

gitで管理します。
$shellFilePath はシェルファイルのパスです。
ビルド番号を+1して、ipaとdSYMを作成します。
ファイル名も分かりやすい名前に変えます。

buildForAppStore.sh
#!/bin/bash -l
set -ux
: usage
: '$1=PROVISIONING_PROFILE'

: $1

PROVISIONING_PROFILE=$1
shellFilePath="${WORKSPACE}/jenkins"

# クリーン処理 
. ${shellFilePath}/clean.sh
clean
install

CFBundleShortVersionString=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist`
CFBundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist`

CFBundleVersion=`expr ${CFBundleVersion} + 1`

now=`date +"%Y.%m.%d.%H.%M"`

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${CFBundleVersion}" ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist

xcodebuild -workspace ${WORKSPACE}/<プロジェクト名>/<プロジェクト名>.xcworkspace \
-scheme <プロジェクト名> \
-configuration Release \
archive -archivePath ${WORKSPACE}/build/Release-iphoneos/<プロダクト名>.xcarchive \
CODE_SIGN_IDENTITY='iPhone Distribution: hoge inc. (XXXXXXXXX)' \
PROVISIONING_PROFILE="${PROVISIONING_PROFILE}" \

xcodebuild -exportArchive -archivePath "${WORKSPACE}/build/Release-iphoneos/<プロダクト名>.xcarchive" -exportOptionsPlist "${shellFilePath}/exportOptions_AppStore.plist" -exportPath "${WORKSPACE}/build/Release-iphoneos"
mv ${WORKSPACE}/build/Release-iphoneos/<プロジェクト名>.ipa ${WORKSPACE}/build/Release-iphoneos/<プロジェクト名>-v${CFBundleShortVersionString}-${CFBundleVersion}-${now}.ipa

cd ${WORKSPACE}/build/Release-iphoneos/

zip -r ${WORKSPACE}/build/Release-iphoneos/<プロダクト名>.app.dSYM.zip <プロダクト名>.xcarchive
exportOptions_AppStore.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>method</key>
    <string>app-store</string>
    <key>uploadBitcode</key>
    <true/>
    <key>uploadSymbols</key>
    <false/>
</dict>
</plist>

gitのタグ付け

ビルド番号を変えているのでcommitして、tagも作成してpushします。

createTag.sh
#!/bin/bash -l
set -ux

CFBundleShortVersionString=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist`
CFBundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist`

# タグを付ける
tagName=`echo v${CFBundleShortVersionString}.${CFBundleVersion}`

echo "tagName:"${tagName}

git add  ${WORKSPACE}/<プロジェクト名>/Supporting\ Files/<プロジェクト名>-Info.plist
git commit -m "jenkins自動コミット"

if [ $? -ne 0 ]; then
  echo "commit 失敗しました"
  exit 1;
fi

git push origin HEAD:release
git tag -a ${tagName} -m "申請バージョン"
git push origin ${tagName}

exit $?

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2