Skip to content

Instantly share code, notes, and snippets.

@shakaib-arif
Last active July 16, 2024 06:43
Show Gist options
  • Save shakaib-arif/c648267883321c0231a771017212f93b to your computer and use it in GitHub Desktop.
Save shakaib-arif/c648267883321c0231a771017212f93b to your computer and use it in GitHub Desktop.
Azure Pipeline: iOS Application with App Extension

Pipeline: iOS Application with App Extension

Unfortunately there is not a straight forward way for the iOS application with App extension in Azure. But to make it work you'll have to do a couple of changes in the project that I'll share later.

Azure Pipeline: Xcode task

As per my recent experience to create the pipeline for such sort of application, the given xcode task from Azure is not capable to handle this case.

And I have later confirmed this from the PG team by reaching out to Azure DevOps support.

"The current version Xcode@5 has the limitation to build the application with App extension."

Project configuration

  1. Modify project file project.pbxproj
  2. Use xcodebuild command in terminal to compile commands for the pipeline

We have modified the project configuration in project.pbxproj file as proposed in the following link.

https://stackoverflow.com/a/29605731/3611427

This way we have a variable for each provisioning profile and later in the terminal we can assign values to it. I have gathered few commands to build and archive and used the same in

Workaround

Declare the following variables.

signingIdentity='iPhone Distribution: XXXX YYYY'
sdkOption='iphoneos'
configurationOption='Release'
workspaceName='MyApplication.xcworkspace'
schemeName='MyApplication'
APP_PROFILE_ID='00110011-0011-101-0011-000011110000'
APP_EXT_PROFILE_ID='00110011-0011-101-0011-000011110000'

Build Command

/usr/bin/xcodebuild -sdk $sdkOption -configuration $configurationOption -workspace $workspaceName -scheme "$schemeName" build -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$signingIdentity" APP_PROFILE="$APP_PROFILE_ID"  EXTENSION_PROFILE="$APP_EXT_PROFILE_ID"

Archive Command

/usr/bin/xcodebuild -sdk $sdkOption -configuration $configurationOption -workspace $workspaceName -scheme "$schemeName" archive -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$signingIdentity" APP_PROFILE="$APP_PROFILE_ID"  EXTENSION_PROFILE="$APP_EXT_PROFILE_ID"

Export Command

/usr/bin/xcodebuild -exportArchive -archivePath ~/Desktop/TestBuild.xcarchive -exportOptionsPlist $Build.SourcesDirectory/MyApplication-Info.plist -exportPath ~/Desktop/MyApplication.ipa
pool:
name: Azure Pipelines
demands: xcode
variables:
certSecureFileName: 'Certificates.p12'
P12Password: 'SomeStrongPassword2021!'
signingIdentity: 'iPhone Distribution: XXXX YYYY'
provProfileSecureFileOne: 'MyApplication.mobileprovision'
provProfileSecureFileTwo: 'OneSignal.mobileprovision'
sdkOption: 'iphoneos'
configurationOption: 'Release'
workspaceName: 'MyApplication.xcworkspace'
schemeName: 'MyApplication'
APP_PROFILE_ID: 00110011-0011-101-0011-000011110000
APP_EXT_PROFILE_ID: 00110011-0011-101-0011-000011110000
ArchivePath: ~/Desktop/TestBuild.xcarchive
ExportIpaPath: ~/Desktop/MyApplication.ipa
steps:
- task: InstallAppleCertificate@2
displayName: 'Install Certificates'
inputs:
certSecureFile: '$(certSecureFileName)'
certPwd: '$(P12Password)'
signingIdentity: '$(signingIdentity)'
- task: InstallAppleProvisioningProfile@1
displayName: 'Install App provisioning profile'
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: '$(provProfileSecureFileOne)'
- task: InstallAppleProvisioningProfile@1
displayName: 'Install App Extension (OneSignal) provisioning profile'
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: '$(provProfileSecureFileTwo)'
- task: CmdLine@2
inputs:
script: |
echo "Carthage installation"
cd $(Build.SourcesDirectory)
carthage update --platform iOS
displayName: 'Carthage dependencies'
- task: CmdLine@2
inputs:
script: |
echo "Pod installation"
cd $(Build.SourcesDirectory)
pod install
displayName: 'CocoaPods install'
- task: CmdLine@2
inputs:
script: |
echo "Build iOS app"
cd $(Build.SourcesDirectory)
/usr/bin/xcodebuild -sdk $(sdkOption) -configuration $(configurationOption) -workspace $(workspaceName) -scheme "$(schemeName)" build -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$(signingIdentity)" APP_PROFILE="$(APP_PROFILE_ID)" EXTENSION_PROFILE="$(APP_EXT_PROFILE_ID)"
displayName: 'Xcode Buid'
- task: CmdLine@2
inputs:
script: |
echo "Archive the iOS app"
cd $(Build.SourcesDirectory)
/usr/bin/xcodebuild -sdk $(sdkOption) -configuration $(configurationOption) -workspace $(workspaceName) -scheme "$(schemeName)" archive -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$(signingIdentity)" APP_PROFILE="$(APP_PROFILE_ID)" EXTENSION_PROFILE="$(APP_EXT_PROFILE_ID)" -archivePath $(ArchivePath)
displayName: 'Xcode Archive'
- task: CmdLine@2
inputs:
script: |
/usr/bin/xcodebuild -exportArchive -archivePath $(ArchivePath) -exportOptionsPlist $(Build.SourcesDirectory)/MyApplication-Info.plist -exportPath $(ExportIpaPath)
displayName: 'Xcode Export'
@wojtek717
Copy link

It saved me <3

@mihael-weareyou
Copy link

Thank you for this :)

Copy link

ghost commented Nov 10, 2022

This is really good

@shameemshah
Copy link

Thankyouu

Copy link

ghost commented Dec 20, 2022

I think we can avoid the 'Xcode Buid' task since 'Xcode Archive' does build by itself before archiving , tried it out & its working

@Saikishore031
Copy link

Still am facing the same issue, build is getting completed but the app is crashing when installing in iOS device, same code is working in my local machine. Please help me on this

@sanrossi
Copy link

it's work. thx

@ol-v-er
Copy link

ol-v-er commented Jul 16, 2024

This was exactly what i needed.
Works fine on the Azure pipeline task.

On the command line, there is one modifications to make the match the export phase. You need to add the -archivePath ~/Desktop/TestBuild.xcarchive :

Archive Command

/usr/bin/xcodebuild -sdk $sdkOption -configuration $configurationOption -workspace $workspaceName -scheme "$schemeName" archive -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$signingIdentity" APP_PROFILE="$APP_PROFILE_ID"  EXTENSION_PROFILE="$APP_EXT_PROFILE_ID" -archivePath ~/Desktop/TestBuild.xcarchive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment