Technology
4 min
GitLab CI/CD allows you to build, test, and publish software without needing a third-party integration or application. GitLab CI/CD fits in a common development workflow. You can start by discussing a code implementation in an issue and working locally on your proposed changes.
By Mohammad Jeeshan
16 Feb, 2022
CI ( Continuous Integration ) / CD( Continuous Delivery ) are commonly used combined practices in the S/W development field that help developers incrementally compile, pack, link, and integrate code changes.
Not only this, but they (CI and CD) are also assisting a lot in defeating the existing software anomalies and side-by-side increasing productivity of intermediate, beginner-level, or advanced developers by helping them create a newer software version—without ignoring every aspect of SDLC.
Let’s know about CI-CD using GitLab.
Continuous integration (CI) is an excellent tool for helping developers be more productive and write higher-quality code. And its best part is that every developer can recognize the modifications/ changes in the codebase by running (actively) a collection of quality tests, thereby making integration(s) swifter and flexible.
In short, continuous delivery begins its play at an instance CI’s process completes. Furthermore, apps/ applications to be delivered according to computing environments are automated so that team(s) may work with utmost flexibility, keeping in mind all the aspects of testing/ development. And such a sorted approach works miracles at times changes in complex/ mid-level codes are pushed to appropriate production environments.
Note: This post will assist in offering a step-by-step guide that a developer may use to set up GitLab CI for any iOS projects. And all this must be implemented from the initial point till the finish.
The time has now come to follow the listed-below footprints: -
What happens if these options are not enabled in your project?
Don’t worry; I am here to rescue you from this situation. You have two options.
The first one is you can add these options to your existing project.
You can continue without including these options, which means you can implement CI-CD without including the Unit test.
But remember one thing: -
“If you don’t include Unit Test in your project, then you can’t run auto unit test script in your .yml file.”
So ensure your .yml file doesn’t contain any unit test-related script; otherwise, our pipeline will fail.
Now you are thinking about what is script & pipeline. Don’t worry. I’m here.
Let's first understand what a script is. & why are we using it here?
By sharing your scheme, GitLab CI gets the context it needs to build and test your project by sharing your scheme. It's imperative to don’t forget to share your project's schemes.
curl-o.gitignore https://www.toptal.com/developers/gitignore/api/swift
Now you are thinking, What is xcpretty, and why do we use it?
In clear-&-crisp words, pretty is undoubtedly an easy-to-use, scalable, plus (+) efficient formattor for the command-line Xcodebuild tool. And at times, Xcode steps ahead for testing and building your futuristic/ current Gitlab project, there this command-line tool amazingly transforms the output in a readable format. Thereafter, xcpretty reads (the obtained output) in an easy-peasy manner.
How to install xcpretty on your mac?
It's straightforward - just run your terminal's gem install xcpretty command. And boom - it will automatically download xcpretty in your mac machine.
For better installation understanding, the aforementioned link works
Before installing GitLab runner, let’s discuss first: What is GitLab-runner?
GitLab Runner application works brilliantly with GitLab CI (it means Continuous Integration)/CD (Continuous Delivery) for running the assigned/ unassigned jobs well in the selected/ not-selected pipeline.
Basically, GitLab Runner is open-source and written in the Go programming language. One can flexibly execute/run this as binary or single; no dire need to explain language-specific requirements. You can proceed with the secure and easy-to-implement installation instructions of GitLab Runner, which can supportively execute on Windows, Macintosh, or other operating systems.
For more information about the Gitlab Runner, please go through the following link https://docs.gitlab.com/runner/
Next Question: How to install Gitlab-Runner on Mac OS?
For this, I am adding an official link on how to install Gitlab-Runner on Mac OS? https://docs.gitlab.com/runner/install/osx.html. In this link, you can see there are two methods to install GitLab-runner:
In my case, I tried both methods, but I really like the Homebrew method. However, GitLab does not maintain the Homebrew formula but don’t worry; Homebrew maintains their services by themselves.
For more info:- https://formulae.brew.sh/formula/gitlab-runner
It's important to your CI-CD implementation, but don’t worry.
This is an important part. You should enter unique tags, for example, MjCI, MjCD. in my case. Why should it be unique?
Suppose you get any error while you run the GitLab-runner start command, don't panic.
Don’t worry; I have a solution for this error, and it should work. Just run the brew command, which is brew services start GitLab-runner. For this command, make sure you have installed brew on your Mac. If it is not installed on your Mac, then go through this link https://brew.sh/
It’s not a proper solution, but it works for me. You can also try this.
But to make sure our runner is working in our local machine for this, just run the Gitlab-runner verify command.
Here you can see that my two runners are alive this time, which I can use. You can also verify that its token number is the same.
You can read How to write a .yml script in detail by following these links.
My experience: I want to tell you what problem I faced while writing a script for my .yml file. I was getting a different type of error when I pushed my code.
Sometimes, I get an invalid .yml format.
Solution: When you write any script just for confirmation, follow this link http://www.yamllint.com/ . Basically, it’s an online .yml validator tool.
Sometimes, my pipeline is stuck.
Solution: if your pipeline status displays as stuck, then you have made two mistakes; first, your runner is not online, which you are using.
For this, just run the GitLab-runner verify command, as we know. If your the runner is alive, then 100% sure your script format is correct, but you have added some deprecated or unknown lines in your .yml file.
Note: I don’t know why GitLab allows the wrong keywords or lines. In my case, I wasted 4-5 hours trying to know why my pipeline status was showing stuck when my runner status is showing online & alive.
Sometimes, my pipeline status fails.
Solution: Suppose all is good in your case means your runner is online and your .yml script is also good, but you also get pipeline failure. In that case, my suggestion is to please write a simple script. For example: -
stages:
- build
build_project:
stage: build
script:
- echo 1st Script Executing.
tags:
- CD-CI
Here I am defining only one stage for my pipeline - Which name is built, and within this stage, I am just printing a simple text line? You should also try this first before doing any advanced things.
Ensure tags are the same as you enter during the runner registration time. If you forgot, don’t worry; you can check these tags in the project settings where you see your runner.
You can also run the script without adding tags, but it works only when you have a single runner register with your machine.
For more information on implementing CI-CD, please go through this link.
Setting up GitLab CI for iOS projects
Hi, I am sharing my .yml file, which will help you understand how it works.
stages:
- build
- testing
- archive
build_project:
stage: build
script:
- echo 1st Script Executing
- xcodebuild clean
-project TestingCi.xcodeproj
-scheme TestingCi | xcpretty tags:
- CD-CI
build_testing:
stage: testing
script:
- echo 2nd Script Executing
- xcodebuild clean
-project TestingCi.xcodeproj
-scheme TestingCi | xcpretty
- xcodebuild test
-project TestingCi.xcodeproj
-scheme TestingCi
-destination 'platform=iOS Simulator,name=iPhone 8,OS=15.0' | xcpretty -s
tags:
- CD-CI
archive_project:
stage: archive
script:
- echo 3rd Script Executing
- xcodebuild clean archive
-archivePath build/TestingCi
-scheme TestingCi
- xcodebuild
-project TestingCi.xcodeproj
-scheme TestingCi -archivePath /Path/To/Output/TestingCi.xcarchive archive
only:
- master
artifacts:
paths:
- build/
tags:
- CD-CI
After this, your project will automatically achieve, and you can also download your .ipa from your GitLab project. If you are testing, please remove only: - master lines from your .yml file if you are testing. These lines mean your archive stage runs only when anyone commits on the master branch.
How to Publish iOS apps to the App Store or TestFlight?
Thereafter, automating every single aspect of your development and later releasing the required workflows won't be that challenging!!
Now the next question is How to install Fastlane on a local machine?
There are two ways to install Fastlane on a local machine. The first one uses brew, while the second one uses gem. I personally recommend you; please choose option one using brew. For this, you go to the terminal and run brew install Fastlane. You can also check this link https://formulae.brew.sh/formula/fastlane .
After installing Fastlane in your mac, you have to initialize Fastlane for your project. For this, go to the project directory using the terminal & run fastlane init command. Before running this command, please read these lines also.
https://docs.fastlane.tools/getting-started/ios/setup/ (Normal version)
https://docs.fastlane.tools/getting-started/ios/fastlane-swift/ (Beta version)
All above-given links are official, which I also follow during CI- CDimplementation. One thing if you are using the Fastlane beta (Fastlane init swift)command, then please follow this link
Auto-deploy iOS app to TestFlight using Gitlab CI and Fastlane
I think these links are sufficient to explain well about Fastlane - how to use it with the IOS project??
Building a High-performance Ecommerce App with React Native
By Ayushi Shrivastava
5 min read
Personalisation in Mobile Apps: Boosting Engagement with AI
By Ayushi Shrivastava
5 min read
Developing iOS Apps for Wearables with watchOS & HealthKit
By Ayushi Shrivastava
5 min read
Mastering Cross-Platform Mobile App Development: Balancing Performance, UX, and Scalability in Multi-Environment Deployments
By Ayushi Shrivastava
5 min read
Technology
5 min
Building a high-performing e-commerce app? Learn how React Native transforming the future and delivers amazing results. Read this blog to build a successful React Native ecommerce app to improve the sales. Covering the features, step-by-by-step process, comparison with Flutter, etc. Give a read!
Technology
5 min
Personalization in mobile apps is the key driver to boost customer engagement. Read this blog to get insights of AI-driven techniques and real-world success stories to enhance your app's user experience and brand reputation.
Technology
5 min
Wearables and fitness trackers are transforming lifestyles, with the market expected to reach $41.3 billion. This blog explores developing iOS wearable apps using watchOS and HealthKit, covering interface design, HealthKit integration, testing, and compliance with Apple guidelines. Learn strategies to create seamless, user-centric apps for fitness, health monitoring, and productivity.
Feeling lost!! Book a slot and get answers to all your industry-relevant doubts