Implementing CI/CD for Flutter with Jenkins & BitBucket

Discover the power of Continuous Integration and Continuous Deployment (CI/CD) for your Flutter projects! With this write-up, we unveil the secrets of setting up an efficient CI/CD pipeline using two industry-leading tools.

author

By Vinamra Singh

09 Jun, 2023

In today's fast-paced software development landscape, ensuring the efficient and reliable delivery of applications is paramount. Implementing a CI/CD (Continuous Integration/Continuous Deployment) pipeline for Flutter projects can significantly streamline the development process, enabling faster feedback, automated testing, and smooth deployments.

By combining the power of Jenkins, an automation server, with BitBucket, a version control repository, developers can establish a robust CI/CD pipeline for their Flutter projects. But how can you set up the CI/CD pipeline for your Flutter projects using Jenkins and BitBucket? This blog will explore how to implement CI-CD using Jenkins with BitBucket repos.

https://quokkalabs.com/blog/flutter-mobile-app-development-guide/

Flutter Mobile App Development- The Definitive Guide
Flutter mobile app development- why startups and enterprises should choose over other...
https://quokkalabs.com/blog/flutter-mobile-app-development-guide/
link image

Let's start with a brief introduction to CI/CD pipeline & Jenkins.

What is CI/CD Pipeline?

A CI/CD pipeline is a set of automated processes and tools that enable developers to integrate code changes, test them, and deploy the application consistently and efficiently. In the context of Flutter projects, a CI/CD pipeline helps streamline the development workflow, automate build and test processes, and ensure the smooth deployment of Flutter applications

Workflow of CI/CD Workflow of CI/CD

How CI/CD Pipeline Works for Flutter Projects

In Case of Continuous Integration (CI):

CI regularly merges code changes from multiple developers into a shared repository. It involves committing code changes to a version control system like BitBucket for Flutter projects whenever a developer completes a task or adds a feature.

The CI pipeline for Flutter projects typically involves the following steps:

  • Code Integration: Hire flutter developer who push some changes to the repository, triggering a CI system like Jenkins.
  • Building: The CI system pulls the latest code, installs necessary dependencies, and builds the Flutter application.
  • Automated Testing: The CI system runs automated tests to verify the quality and functionality of the code.
  • Test Reports: The CI system generates test reports, providing developers with insights into any issues or failures.
  • Code Quality Checks: Additional checks like code formatting, linting, and static analysis may be performed to maintain code quality standards.
  • Notifications: The CI system notifies developers of the build status and test results, facilitating quick feedback and issue resolution.

In Case of Continuous Deployment (CD):

CD focuses on automating the application's deployment to production or staging environments after successful integration and testing. CD involves packaging the application for Flutter projects, generating release artifacts (e.g., APK or IPA files), and deploying them to the target platforms or servers.

The CD pipeline for Flutter projects typically includes the following steps:

  • Artifact Generation: Once the CI pipeline is complete and the build passes all tests, the application is packaged, and release artifacts are generated.
  • Distribution: The generated artifacts, such as APK files for Android or IPA files for iOS, are distributed to the appropriate distribution channels (e.g., app stores and staging servers).
  • Deployment Automation: The deployment process is automated, ensuring that the new version of the application is seamlessly deployed to the target environment.
  • Post-Deployment Tasks: Additional actions like database migrations, cache warming, or server restarts may be performed after deployment.

NOTE: Besides Jenkins, several other ways exist to achieve a CI/CD workflow. Some popular options are GitHub Action, CircleCI, GitLab CI/CD, Travis CI, AWS CodePipeline, Bamboo, etc.

What is Jenkins?

What is Jenkins? Jenkins is an open-source automation server that facilitates continuous integration and delivery of software projects. It provides a robust platform for automating various stages of the software development lifecycle, including building, testing, and deploying applications. Jenkins is highly flexible and extensible, supporting various plugins and integrations with other tools and technologies.

What is New in Flutter 3.3?

Some key Features & Functionalities of Jenkins:

  • Continuous Integration: Jenkins is primarily known for its CI capabilities. It allows developers to regularly integrate code changes from multiple contributors into a shared repository. Jenkins can automatically trigger builds whenever changes are pushed to the repository, enabling early detection of integration issues.

  • Build Automation: Jenkins supports the automation of build processes. It can pull the latest code changes from version control, compile the code, and create build artifacts, such as executable files or deployable packages. Jenkins provides extensive support for various build tools and technologies, including support for Flutter projects.

  • Testing & Quality Assurance: Jenkins enables the execution of automated tests as part of the CI pipeline. It can run unit tests, integration tests, and other types of tests to ensure the quality and functionality of the code. Jenkins can generate reports and metrics based on the test results, helping developers identify and address issues quickly.

  • Plugin Ecosystem: Jenkins has many plugins that extend its functionality. These plugins cover many areas, such as version control systems, build tools, testing frameworks, deployment technologies, and notification systems. Developers can leverage these plugins to customize and enhance their Jenkins pipelines according to project requirements.

  • Scalability & Distribution: Jenkins is designed to handle large-scale projects and distribute build and test workloads across multiple machines or agents. This allows for parallel execution of tasks, reducing build times and increasing overall efficiency.

  • Extensibility: Jenkins provides a flexible architecture that allows developers to create custom plugins and integrations. This extensibility enables Jenkins to integrate with various tools, technologies, and services in the software development ecosystem, making it adaptable to diverse project environments.

  • Community & Support: Jenkins has a vibrant community of users and contributors who actively develop plugins, provide support, and share best practices. This active community ensures that Jenkins remains up to date with the latest industry trends and fosters a collaborative environment for knowledge exchange.

  • Open-Source & User friendly: Jenkins is free to use and has a large community of developers contributing to its ecosystem. It offers numerous plugins that enhance its functionality. Jenkins can be scaled to meet the needs of even the largest organizations. It has a user-friendly web interface that makes it easy to get started.

Overall, Jenkins is a powerful automation server that facilitates continuous integration and delivery. It enables developers to automate build, test, and deployment processes, resulting in faster feedback, improved software quality, and streamlined development workflows.

Now, let’s check out the step-by-step Implementation of CI/CD using Jenkins.

Implementing CI-CD Pipeline Using Jenkins

Step 1: Install Jenkins on your Mac or VM

  • Install the latest LTS version: brew install jenkins-lts
  • Install a specific LTS version: brew install jenkins-lts@YOUR_VERSION
  • Start the Jenkins service: brew services start jenkins-lts
  • Restart the Jenkins service: brew services restart jenkins-lts
  • Update the Jenkins version: brew upgrade jenkins-lts
  • Uninstall the Jenkins: brew uninstall jenkins-lts

Note: *You can also follow this- macOS Installers for Jenkins LTS to learn more about the installation process. It’s configured with http port 8080, so now you can access the Jenkins panel from your local host.

  • The first time, it will ask you for an Administrator Password which you can find out under the secrets folder. For Example: /Users/mj-siddiqui/.jenkins/secrets/initialAdminPassword Step 1.1
  • Now install the suggested plugins. You can also install the plugins manually. This process takes 30–45 mins. Step 1.2
  • Now create an Admin User & Start Jenkins. Step 1.3

Step 2: Create A New Pipeline

  • Click on New Item to create a new pipeline. Step 2.1
  • Enter the item name & select FreeStyle project. You can also go with the other Pipeline option. Step 2.2

Step 3: Configure Pipeline

  • Add descriptions to your pipelines and link your Git repository to a Jenkins server. Just enter your c URL & credentials. To add new credentials, click on the "Add" button. Step 3.1
  • Now, choose 'Global credentials' as the domain, select 'UserName' and 'Password' as the Kind, and leave the scope as default. Here you have two options: The first one is to enter your BitBucket userName & Password. The second one is just adding your BitBucket app Password as an ID. Step 3.2 Note: Here, we are using my BitBucket app password. You can generate a new password with the help of this- Create an App password. You can also specify the branch name (This branch will be used as the latest code when the pipeline is triggered). You can leave the repository browser as auto; otherwise, you can manually specify a repository browser like Gitlab, GitHub, BitBucket, etc.*

Read More: CI-CD using GitLab

Step 4: Write Script

Before writing the script, let's discuss some essential points related to the script.

  • Build Trigger: We can use this feature/option to manage our pipeline trigger behavior. For more context, please click on the Question icon.
    Step 4.1
  • Build Environment: Here, we set some configurations and settings that define the build process's environment. It allows you to customize and control various aspects of the build, such as setting up required tools, defining environment variables, configuring build parameters, and more. Step 4.2
  • Build Steps: We write pipeline script steps and how the pipeline will react. Step 4.3
  • Post-Build Actions: If you want to perform some action after the build steps run successfully, you can use this feature. Step 4.4

Script: (Test Pass)

APPLE_ID="bhanupratap.yadav@quokkalabs.com" APPLE_ID_PASSWORD="${App_Specific_Pass}" 
flutter clean  
flutter pub get  
# First Creating & Uploading iOS Build  
flutter build ipa --no-tree-shake-icons IPA_PATH="$JENKINS_HOME/workspace/demo/build/ios/ipa/demo.ipa" 
xcrun altool --upload-app -f "$IPA_PATH" -t ios -u "$APPLE_ID" -p "$APPLE_ID_PASSWORD" --verbose  
# Here Creating Android Build 
flutter build appbundle --release --no-tree-shake-icons

Note 1: Here we are using the google-play-android-publisher plugin to upload a build. For more context, please follow the given link: https://plugins.jenkins.io/google-play-android-publisher/ Note-1 Note 2: no-tree-shake-icons (Adding this line just to ignore flutter default AppIcon). If you have a real app, then no need to add this line.

Note 3: We can also use the ngrok app for this (BitBucket repos.) process. It is a simplified API-first ingress-as-a-service that adds connectivity, security, and observability to your apps in one line.

Various Challenges Faced by Developers While Implementing Jenkins

Implementing Jenkins can come with several challenges that developers may encounter. Here are some common difficulties faced during the implementation process:

Challenge 1: Flutter command may not be recognized. Challenge 1 Reason: The Jenkins server could not find Flutter, so ensure you have installed Flutter & required software like Android Studio & Xcode on your machine. Also, ensure you have added the Flutter SDK path to the Jenkins server.

Challenge 2: Generate signed AAB file failed Challenge 2 Reason: Don't forget to configure the release build in my app build.gradle file. So, ensure you have added it already.

Challenge 3: Generate IPA file failed.

Reason: If you didn’t configure the provisioning profile & certificate. Also, ensure all things are configured in your Xcode.

Challenge 4: AAB file upload sometimes failed.

Reason: You should have owner access to your Google Service Account. The rollout percentage should be zero when uploading a build as a draft.

That’s it!!!

By following these steps, you can establish a robust CI/CD pipeline for your Flutter projects using Jenkins & BitBucket. This pipeline will enable continuous integration, automated testing, artifact generation, and deployment automation, ensuring your Flutter applications are built, tested, and deployed efficiently.

Hence, Implementing a CI/CD pipeline enhances collaboration among developers and promotes faster, more reliable software releases, ultimately improving the success of your Flutter projects. Thanks!!!

Read More: Implementing CI/CD Using GitHub Actions: A Quick Guide to Build a CI/CD Pipeline

Frequently Asked Questions

Q1. What is Bitbucket, and why should we use it?

Ans: Bitbucket is a web-based version control repository hosting service. It provides features like Git and Mercurial repositories, pull requests, and issue tracking. Using Bitbucket allows us to manage the Flutter project's source code and collaborate with a team.

Q2. How often should we trigger CI/CD pipeline builds?

Ans: The frequency of triggering builds depends on your development workflow and requirements. Common approaches include triggering builds on every commit, on a schedule (e.g., nightly builds), or when specific events occur (e.g., pull requests or tag creation).

Q3. Can we use Jenkins to deploy my Flutter app to app stores?

Ans: While Jenkins can build and package your Flutter app, deploying app stores requires additional steps specific to each store's guidelines and tools. Jenkins can be configured to trigger these deployment steps, but you must set up the appropriate tools and credentials for each app store.

Q4. Are there any alternatives to Jenkins for CI/CD?

Ans: Yes, there are several alternatives to Jenkins for CI/CD, such as GitLab CI/CD, CircleCI, Travis CI, and Azure DevOps.

Q5. Can we use other version control systems with Jenkins, like GitHub or GitLab?

Ans: Yes, Jenkins supports integration with various version control systems, including GitHub, GitLab, and Bitbucket.

How many Flutter app development companies are there in the US?

Determining the precise count of Flutter app development companies in US proves challenging due to the industry's expansive and ever-evolving nature. Nonetheless, the landscape hosts thousands of such companies, spanning from petite boutique establishments to expansive multinational agencies.

Tags

ContinuousDeployment

ContinuousIntegration

Automation

FlutterDevelopment

BitBucket

Jenkins

CI_CD

SoftwareDevelopment

DevOps

Similar blogs

Let’s Start a conversation!

Share your project ideas with us !

Talk to our subject expert for your project!

Feeling lost!! Book a slot and get answers to all your industry-relevant doubts

Subscribe QL Newsletter

Stay ahead of the curve on the latest industry news and trends by subscribing to our newsletter today. As a subscriber, you'll receive regular emails packed with valuable insights, expert opinions, and exclusive content from industry leaders.