Fixing a critical bug in your code can save the integrity of your project.
What is equally important is continuously improving the quality of the code, testing, and automating it for new release. Developers must make sure they follow all these processes while seamlessly communicating the changes with their team members.
That’s why development teams across the world practice a mechanism called Continuous Integration (CI) and Continuous Delivery (CD).
Starting from generating a build using command line, uploading build to test flight using fast lane, interfacing Jenkins with bitbucket and Fastlane, CICD mechanism can simplify and automate the process of build generation for iOS developers.
We are coming up with a 3-part series covering the A-Z of deploying CI/CD mechanism for automating build generation.
In this blog, we will be talking about generating a local build using command line.
Let’s dive in.
This blog is written by Ranjith Ravichandran, Senior SDE, Product Engineering at M2P.
What is CI/CD?
Continuous Integration is the practice of merging code changes to a shared repository many times a day. It includes automated building generation and testing.
Continuous Delivery is continuous integration with additional processes which allows application release to the customers after each change or update.
Continuous integration and continuous delivery (CI/CD) is a critical component of agile software development, which emphasizes the importance of delivering working software to users quickly and frequently. This allows stakeholders and users to access newly created features and provide feedback as soon as possible, so features can be iteratively improved.
CI/CD is a valuable tool for software developers, regardless of the size of their team. For solo developers, CD may be even more important, as it can help to ensure that software is delivered to users quickly and reliably.
In this blog, we will show you the behind the scenes of building, testing, archiving, and uploading an iOS application. Being aware of the native Apple developer tools and learning command line interaction is integral for anyone using CI/CD mechanism.
Command line interactions can help you with the following.
- Understanding apple technologies used for building and deploying an iOS application
- Automating iOS development task for continuous integration or cloud-based servers
- Understanding the background working of tools like Fastlane
Automating Build Generation – Overall Process
- Setting up the project and creating a repository in Bit Bucket
- Connecting local Jenkins with Bit Bucket cloud to check out as project branch (to build as an IPA)
- Connecting Jenkins and Fastlane for building and archiving the project
- Moving the archived IPA to TestFlight from Fastlane
Build Generation using Command Line
Let’s assume that a project is developed by multiple engineers where they all must perform the following.
- Checking out the project from Bit Bucket to local system
- Archiving the particular branch of the project using command line
After following the above processes, the IPA is generated inside the project folder.
To understand the command line deployment process, we should have the following things set up in advance before starting the build generation.
- Sample app with Xcode workspace – e.g., FintechBase.xcworkspace
- Xcode Scheme with Release configuration – e.g., Developement
- Certificates, AppID, Provisioning profiles setup for production in iTunes Connect – Use Apple’s documentation for setting up
- macOS with Distribution certificate in the keychain
We perform static analysis of the source code. The xcodebuild has the ability to clean and analyze the source code for any common syntax errors.
Code for analyzing the project using the terminal
xcodebuild – workspace FintechBase.xcworkspace -scheme Development -sdk iphonesimulator10.3 clean analyze
We can build an iOS app using xcodebuild ‘build’ action which can generate the derived data for our iOS app. Once the application is built, it can run inside the simulator or can be used by the test bundle.
Build for running
We can simply build our app to run inside simulators by using the command
xcodebuild -workspace FintechBase.xcworkspace -scheme Development -configuration Release -allowProvisioningUpdates build
Most of the iOS engineers face difficulties in archiving an iOS application as it deals with provisioning profiles, certificates, and build configurations.
To upload an app to iTunes Connect or deploy it on to the provisioned devices, we need to build an app for generic iOS device destination as well as export it in the IPA format.
Next step is building our application with release configuration scheme ‘Development’ with generic iOS device destination.
There are two steps involved.
- Building an archive with xcodebuild archive
- Creating the .ipa file with xcodebuild -exportArchive
Without Team ID
xcodebuild archive -workspace FintechBase.xcworkspace -scheme Development clean build archive -archivePath ./build/FintechBase.xcarchive
With Team ID
xcodebuild archive -workspace FintechBase.xcworkspace -scheme Development DEVELOPMENT_TEAM=”XXXXXXXXXX” -allowProvisioningUpdates -archivePath ./build/FintechBase.xcarchive
- The build is created using the above command build/FintechBase.xcarchive
- Replace ‘XXXXXXXXX’ with your team ID
We now export the .ipa using the command
xcodebuild -exportArchive -allowProvisioningUpdates -archivePath ./build/FintechBase.xcarchive -exportPath ./build/ -exportOptionsPlist ./build/ExportOptions.plist
Note that the above command requires a ExportOptions argument that points to a .plist file with export options. For a complete list of what you can put in that plist, run xcodebuild -help.
Create build folder in a project and add ExportOptions.plist
Find the sample code for ExportOptions
<?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“>
- method: (String) The method of distribution, which can be set as any of the following:
- teamID: (String) The development program team identifier.
- signingtyle: (String) Automatic Signing “automatic”, incase of manual signing mention “manual” add provisioningProfiles and signingCertificate
- uploadBitcode: (Boolean) Option to include Bitcode.
- manageAppVersionAndBuildNumber: to ensure that you have already updated your version/build number before archiving
- generateAppStoreInformation: For App Store exports, should Xcode generate App Store Information for uploading with iTMSTransporter. Defaults to NO
- uploadSymbols: Should symbols be stripped from Swift libraries in your IPA. Defaults to YES
After successfully running the command, the ipa file will be generated inside the build folder in the name of FintechBase.ipa
The next step involves automating the build generation using Fastlane and pushing it to TestFlight which we will be covering in the next blog.
Till then, Stay tuned!
Have any questions/suggestions?
Write to us at email@example.com. Our expert team will get in touch with you.
Subscribe to our newsletter and get the latest fintech news, views, and insights, directly to your inbox.