Hola , welcome to my next article. Here we will learn how to automate the whole deployment process . In my last article, I showed you guys how to build the IPA — artifact file through fastlane and also how to manage multiple targets for deployment.
In case you missed my previous article here is the link https://medium.com/@vizllx/integrating-fastlane-with-multiple-target-for-a-single-ios-project-7920b32e1cb4
Continuous integration, for software, is the practice of merging code changes to a shared repository many times a day. For many, it includes automated building and testing.
Continuous delivery, is continuous integration along with additional processes allowing the app to be released to customers after each change or update.
Both CI and CD are not only useful to a big team but also useful if you are a sole developer in a one-man team, CD probably means more to you since delivery is unavoidable to every application developer.On this article we will emphasising on a single objective how to make deployment process faster.
CI/CD is essential to software development using Agile methodologies which recommends the use of automated testing to get working software into the hands of real users as quickly as possible. This allows stakeholders and users to access newly created features and provide feedback as soon as possible, so features can be iteratively improved upon.
I have already showed you how to setup the fastlane for the multiple targets and create different env (Environment) file for individual target for better manageability.
So let us consider we have the following project structure
Single Xcode Project→ multiple targets→ APP1 , APP2 , APP3
So let’s write up our fastlane script to automate the job of uploading beta build in test-flight using Pilot command of fastlane.
Before going further configure your env file and appfile which are in fastlane directory how I have done in the following gist -:
Here is the fastlane script which we are using to automate the build for uploading to testflight
In the above script we have the following things which I need to clarify -
1. We are unlocking the keychain for Jenkins job which we will setup later in this article.
2. Cleaning up artifacts , derived data and pod cache for getting a clean build
This are plugins used with fastlane to add versioning and testing features within the script. As you can see I am using the “increment_build_number_in_plist” command to increment the version number whenever the build is run.
You might be wondering how to add plugin in fastlane , it’s simple just add the following in your pluginfile which is generated by Fastlane
4. The fastane-gym command used to build , archive and create IPA. For more details how I have configured Gym and project scheme you can refer my last article https://medium.com/@vizllx/integrating-fastlane-with-multiple-target-for-a-single-ios-project-7920b32e1cb4
5. We are using Pilot to upload the build in Test-flight and make sure the app all the information is filled before uploading the build .
Currently I have a group called “testers” which include external testers so that is the reason in the pilot command I have added — groups: [“testers”] -, if you want to distribute among internal testers then you can delete that line.
6. The environment variable FASTLANE_PASSWORD is used to provide your itunes-connect password so that when fastlane tries to upload the build then it can provide the credentials from Appfile and this environment variable.
7. At last we are sending an update through slack that the build is archived and uploaded successfully to test-flight through slack-web hook, which is very easy to configure in slack if you know the basics. You can check this link to learn more about slack-web hook → https://bit.ly/2n6eS1Q
Setting up Jenkins Job
Jenkins is an automation server that helps you to perform the CI/CD tasks. It runs a web GUI interface and is pretty easy to customize, so it’s a great choice for an agile team.
Jenkins is on the bleeding edge of technology today. It is also one of the most compelling technologies of the last decade in terms of its disruption to software development and operation practices.
The Jenkins Continuous Integration solution has become a standby in organizations of all sizes that want to increase productivity and streamline software development in the era of Agile. It has extensive community support has the extended the core functionality of Jenkins by developing thousands of useful plugins.
Now we will be configuring Jenkins to run the fastlane job.For installing Jenkins you can directly go this link which will give you a kickstart https://gist.github.com/ostinelli/972cfdb4bce51d428d3b
Create a Jenkins build job
- Create a new Freestyle project. Provide Item name and click on OK.
- Configure Git in the Source Code Management section, so that every time you run the Jenkins build job it takes the latest code from your repository.
3. In the Build Environment section , inject the following environment variables in Jenkins as in my case I was getting UTF8 / shell encoding error from Fastlane . I have also reported it as an issue in fastlane https://github.com/fastlane/fastlane/issues/12164
4. Now in the build section, we will add the fastlane script to automate the process of uploading build in Test-Flight . Here also we will include the script for injecting few environment variables to fix the shell UTF8 encoding error comes for fastlane.
5. Now save the build job , go to the Jenkins dashboard and execute it.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — -
I didn’t want to make this tutorial complex so I tried to avoid few steps to make things simpler. But I need you guys to avoid hard-coding the itunes-connect & login keychain password in fastlane script as the fastfile will be present in project source-code and also in your Git server which might give others to get access to your itunes connect account and also your server login password.
You can easily set this variable as Environment variable in Jenkins build script so that no one has the access to the credentials.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
Now you can automate the whole process of deployment to testflight in a click , no need to manual setup your build every-time for uploading it to testflight.
There are numerous options for setting up CI & CD. Depending on your situation. If you like customizing an open source project and running it yourself, Jenkins might be for you. Still, if you have highly specialized needs or need to customize everything imaginable, you might decide to write something entirely from scratch.
So far, Jenkins has offered us a way to quickly setup CI & CD and scale it
In the next article I will show you the next level of automating the task through fastlane:-
- Uploading build to App-Store through Jenkins
- Automating test-case and code coverage report through Jenkins
- Extracting ipa/artifact from Jenkins build job
Till then Happy coding .
Learn and share your knowledge who knows someone somewhere might be benefit by your small effort.
🍻 Thanks for Reading
Did you like the post?
Give me claps! you can give up to 50 times to the clap, and that many more people find and know this post, and of course… don’t forget to share.
Let’s see that applause!