Version control is paramount in modern software development workflows. Tracking the version of your iOS app development is essential for maintaining a clear history. The tracking practice ensures accurate deployments. Developers use GitLab CI/CD scripts to automate major tasks, including the project version. This blog aims to dissect the two primary methods for retrieving the iOS project version in a GitLab CI script: from the Info.plist file and the pubspec.yaml file. We all scrutinize methods to check iOS app development services in the project version in GitLab. It helps when and if you’re using Flutter.
Let’s get into the details!
Method 1: Retrieving iOS Project Version from Info.plist
The Info.plist file is a crucial component of an iOS app development, containing essential metadata about the application, including its version. Mobile app development relies heavily on GitLab. GitLab CI can extract this version using a simple script.
The following steps explain the method:
1. Access plist:
Initially one needs to ensure that the GitLab CI pipeline has access to the project’s source code. You can achieve this by checking out the repository within your CI script:
stages – build build: stage: build script: – git clone <repository_url> – cd <project_directory> |
2. Branch Selection:
One has to keep in mind to check out the branch under consideration if it is not the default branch. To do that you can fetch and switch to that repository and then add the following lines in your script:
Script – … – git fetch origin <branch_name> – git checkout <branch_name> – git pull |
Use simple text parsing to extract the version from plist.
Here’s an example using grep and awk:
Script – … – IOS_VERSION=$(grep -A1 ‘<key>CFBundleShortVersionString</key>’ ios/Runner/Info.plist | grep ‘<string>’ | sed -e ‘s/<[^>]*>//g’ | awk ‘{$1=$1;print}’) – IOS_BUILD=$(grep -A1 ‘<key>CFBundleVersion</key>’ ios/Runner/Info.plist | grep ‘<string>’ | sed -e ‘s/<[^>]*>//g’ | awk ‘{$1=$1;print}’) – echo “iOS App Version: $IOS_VERSION+$IOS_BUILD” |
The Info.plist file contains various keys and values that define crucial details about an iOS app. Among these, the CFBundleShortVersionString key stores the version number, and the CFBundleVersion key stores the build number. By querying these keys, you can accurately retrieve the version information directly from the source.
Method 2: Retrieving iOS Project Version from pubspec.yaml (For Flutter Projects)
For flutter projects, the version of your iOS app is usually specified in the pubspec.yaml file. This usually is the recommended way because it does not involve management and handling of the version number for iOS and android separately. It defines and eases mobile app development. To extract this version in your GitLab CI script follow the below process:
1. Access yaml:
Similar to the previous method, make sure your CI/CD pipeline checks out the repository and navigates to the project directory. And again make sure to check out the branch if you are not using the default branch by using the steps marked as optional:
stages – build build: stage: build script: – git clone <repository_url> – cd <project_directory> – git fetch origin <branch_name> (optional) – git checkout <branch_name> (optional) – git pull (optional) |
Use simple text parsing to extract the version from the pubspec.yaml file. Here’s an example using grep and awk:
script – … – PUBSPEC_VERSION=$(grep -o ‘version:\ [0-9\.\+]*’ pubspec.yaml | awk ‘{print $2}’) – echo “Pubspec Version: $PUBSPEC_VERSION” |
The pubspec.yaml file is a central configuration file for flutter projects. It contains vital information, including the app’s version. By leveraging basic command-line tools like grep, awk, and sed, you can efficiently extract the version number and use it in your CI pipeline.
However, it should be kept in mind that version control is essential for maintaining a clear history of the project’s progress and facilitating collaboration among team members. With these methods at your disposal, you can confidently manage your iOS project versions using GitLab CI. IOS app development services improve significantly using GitLab CI.
Code Snippets
stages – buildbuild: stage: build script: – git clone <repository_url> – cd <project_directory> – git fetch origin <branch_name> (optional) – git checkout <branch_name> (optional) – git pull (optional) – IOS_VERSION=$(grep -A1 ‘<key>CFBundleShortVersionString</key>’ ios/Runner/Info.plist | grep ‘<string>’ | sed -e ‘s/<[^>]*>//g’ | awk ‘{$1=$1;print}’) – IOS_BUILD=$(grep -A1 ‘<key>CFBundleVersion</key>’ ios/Runner/Info.plist | grep ‘<string>’ | sed -e ‘s/<[^>]*>//g’ | awk ‘{$1=$1;print}’) – echo “iOS App Version: $IOS_VERSION+$IOS_BUILD” – PUBSPEC_VERSION=$(grep -o ‘version:\ [0-9\.\+]*’ pubspec.yaml | awk ‘{print $2}’) – echo “Pubspec Version: $PUBSPEC_VERSION” |
Expanding on Method 1: Working with Info.plist
The Info.plist file serves as a repository of important metadata for iOS applications. Alongside the version number, it stores various details like the app’s bundle identifier, display name, and supported device orientations. When integrating GitLab CI into your iOS project, you can harness the power of this file to streamline version retrieval.
Parsing the Info.plist file involves searching the desired key – in this case, the CFBundleShortVersionString. This key holds the version number in a standard format. The version number is a user-friendly representation of the software’s progress and can help users understand the extent of changes between different releases.
Consider a scenario where multiple developers are collaborating on an iOS project. Inconsistent versioning can lead to confusion and hinder efficient development. By extracting the version number programmatically through the CI/CD pipeline, you create a standardised approach that eliminates the risk of human error.
Flutter has gained widespread popularity due to its cross-platform capabilities and ease of use. If you’re working on a Flutter project, you’ll notice that the pubspec.yaml file is your go-to resource for configuration. Apart from version numbers, this file stores dependencies, author information, and project description.
In the context of GitLab CI, extracting the iOS app’s version from the pubspec.yaml file offers an efficient solution. Leveraging command-line tools simplifies the process, making it easy to integrate into your pipeline. The grep, awk, and sed commands work in harmony to isolate the version number and present it for consumption.
The flutter app development ecosystem embraces a unified approach to version management. By tapping into the pubspec.yaml file, you align your CI/CD practices with Flutter’s philosophy, creating a cohesive environment that resonates with the framework’s principles.
In short, automating the extraction of iOS project versions within GitLab CI scripts enhances your development workflow in more ways than one.
Conclusion
To ensure a streamlined app development process automating the retrieval of your iOS project’s version in a GitLab CI script serves as a valuable step. By using either the Info.plist file or the pubspec.yaml file (for Flutter projects), you can ensure that your deployments are accurate and well-documented. Regardless of the method one pursues, GitLab CI empowers entities and stakeholders to integrate this version retrieval seamlessly into the CI/CD pipeline.
Reach out to us at [email protected] to book a free consultation session with our mobile app development team.
FAQs
Q: What is the GitLab-ci yaml file script?
Ans: The GitLab CI/CD YAML file script is used to define the pipeline stages, jobs, and their configurations for automating the build, test, and deployment process in GitLab’s continuous integration and continuous deployment (CI/CD) pipeline.
Q: How to release a version in GitLab?
Ans: To release a version in GitLab, you can use Git tags to mark a specific commit as a release point. This can be done through the GitLab interface or using Git commands.
Q: How to connect Xcode to GitLab?
Ans: To connect Xcode to GitLab, you can use the built-in version control integration in Xcode. Create a new Xcode project, choose the option to use a remote Git repository, and provide the GitLab repository URL.
Q: What are templates in GitLab-CI?
Ans: In GitLab CI/CD, templates are predefined configurations that can be reused across multiple projects or pipelines. They help standardize the pipeline setup and make it easier to create consistent CI/CD workflows.