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.
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: -
- echo 1st Script Executing.
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.
Hi, I am sharing my .yml file, which will help you understand how it works.
- echo 1st Script Executing
- xcodebuild clean
-scheme TestingCi | xcpretty tags:
- echo 2nd Script Executing
- xcodebuild clean
-scheme TestingCi | xcpretty
- xcodebuild test
-destination 'platform=iOS Simulator,name=iPhone 8,OS=15.0' | xcpretty -s
- echo 3rd Script Executing
- xcodebuild clean archive
-scheme TestingCi -archivePath /Path/To/Output/TestingCi.xcarchive archive
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)
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
I think these links are sufficient to explain well about Fastlane - how to use it with the IOS project??
Mastering Swift 5 for iOS App Development- A Beginner's Guide
By Ayushi Shrivastava
5 min read
Top DevOps Best Practices to Streamline Your Development Pipeline in 2024
By Dhruv Joshi
5 min read
Latest Web Development Technologies- Explore Top 8
By Anupam Singh
8 min read
Latest Cybersecurity Trends- From Innovation to Protection
By Anupam Singh
8 min read
The rise of voice commerce presents business opportunities and challenges. Embracing this trend allows for seamless customer experiences and opens new revenue streams. However, navigating privacy concerns, technical limitations, and maintaining brand identity are critical hurdles to overcome. This blog explores the positives and pitfalls of adapting to voice commerce in today's market.
Dive into our comprehensive beginner's guide to mastering Swift5 for iOS app development. Learn everything you need to know about SwiftUI, from the basics to advanced techniques, and kickstart your journey towards building stunning iOS applications.
Unlock unparalleled agility and efficiency with our comprehensive guide to DevOps best practices in 2024. Streamline your development pipeline and stay ahead in today's DevOps trends in 2024 with Quokka Labs.