You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Jenkins为iOS项目多Target构建IPA安装包?

Hey there! I’ve dealt with this exact multi-target iOS build scenario in Jenkins multiple times, so let me break down the step-by-step configs you need to get both target1 and target2 generating their own .ipa files smoothly.

First, making your job parameterized lets you choose which target to build (or both) on demand. Here’s how:

  • Go to your Jenkins job → Configure → General tab.
  • Check This project is parameterized.
  • Add a Choice Parameter named TARGET_SELECTION with options:
    • target1
    • target2
    • Both
      This gives you flexibility instead of hardcoding a single target.
2. Use Execute Shell for Flexible Build Commands

Skip the Jenkins Xcode plugin for this (it’s less flexible for multi-target setups) and use an Execute shell build step. Write a script that handles each target based on your parameter:

# Create build directories to keep things organized
mkdir -p ./build/ipa/target1
mkdir -p ./build/ipa/target2

# Build and export target1 if selected
if [ "${TARGET_SELECTION}" = "target1" ] || [ "${TARGET_SELECTION}" = "Both" ]; then
  # Clean and archive target1
  xcodebuild clean archive \
    -workspace YourProject.xcworkspace \
    -scheme target1 \
    -configuration Release \
    -archivePath ./build/target1.xcarchive
  
  # Export IPA for target1 (use your specific ExportOptions.plist)
  xcodebuild -exportArchive \
    -archivePath ./build/target1.xcarchive \
    -exportPath ./build/ipa/target1 \
    -exportOptionsPlist ./ExportOptions-target1.plist
fi

# Build and export target2 if selected
if [ "${TARGET_SELECTION}" = "target2" ] || [ "${TARGET_SELECTION}" = "Both" ]; then
  # Clean and archive target2
  xcodebuild clean archive \
    -workspace YourProject.xcworkspace \
    -scheme target2 \
    -configuration Release \
    -archivePath ./build/target2.xcarchive
  
  # Export IPA for target2 (use your specific ExportOptions.plist)
  xcodebuild -exportArchive \
    -archivePath ./build/target2.xcarchive \
    -exportPath ./build/ipa/target2 \
    -exportOptionsPlist ./ExportOptions-target2.plist
fi
3. Prepare Target-Specific ExportOptions.plist Files

Each target might have different code signing or export settings (like ad-hoc vs app store). Generate these plists locally first:

  • Open Xcode, archive one target manually, then export the IPA.
  • Xcode will generate an ExportOptions.plist during export. Copy this, rename it to ExportOptions-target1.plist, and adjust settings if needed (repeat for target2).
  • Commit these plists to your repo so Jenkins can access them.
4. Handle Code Signing Correctly

If your targets use different certificates/provisioning profiles:

  • Ensure both are installed in the Jenkins agent’s keychain. You can add a build step to import them using security import if needed.
  • Alternatively, add code signing flags to your xcodebuild commands:
    xcodebuild clean archive \
      -workspace YourProject.xcworkspace \
      -scheme target1 \
      -configuration Release \
      -archivePath ./build/target1.xcarchive \
      CODE_SIGN_IDENTITY="iPhone Distribution: Your Team ID" \
      PROVISIONING_PROFILE="Your Target1 Provisioning Profile UUID"
    
5. Archive the Generated IPAs in Jenkins

Finally, add a Post-build Actions step to save your IPAs:

  • Select Archive the artifacts.
  • In Files to archive, enter:
    build/ipa/**/*.ipa
    

This will store both IPAs (or the selected one) in Jenkins for easy download.


内容的提问来源于stack exchange,提问作者Jenish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:42:49