Flutter — iOS App Release on AppStore using Bitbucket Pipeline.

Parth Gupta
5 min readJun 27, 2023

--

Bitbucket Pipeline for Flutter Deployment is the most struggling part, especially for iOS.

I have struggled a lot to build a pipeline for iOS. That’s why, I thought let’s help other people who are struggling the same.

Here I will share how to set up a pipeline to deploy an iOS application on Testflight.

Also, I will share the best structure of the Bitbucket pipeline which I am using for it.

This code will surprise you with the ‘Validate iOS App’ and ‘Upload iOS App’ steps.
But don’t worry, I already made a tutorial about how to set up the things for ios validation and upload.

Please go and Check this out 👇

Flutter — iOS App Release on App Store Using CLI.

If you need any help. DM me. ClickHere

✨ — — — Let’s Begin — — — ✨

To understand today’s topic. You have to first understand the Bitbucket Tag. Which uses the most in this pipeline?

Bitbucket TAG

#1 image

It is a file with a bunch of code that can include regular stuff of the manual process. Like setting up the flutter path, android sdk and many more.

image: ghcr.io/cirruslabs/flutter:latest

If you have multiple branches and you want to make separate pipelines for the branches themselves.
Otherwise, you can use ‘default’ instead of ‘custom’ for one pipeline.

Then in the custom tag we are managing 2 branches. ‘main’ and ‘development’ as tag.

pipelines:
custom:
master:
- step:
name: Flutter Build Release APK
script:
- flutter build apk --release

development:
- step:
name: Flutter Clean
script:
- flutter clean
- step:
name: Flutter Build
script:
- flutter pub get

#3 runs-on

[OPTIONAL ->> IF YOU WANT TO RUN YOUR PIPELINE ON YOUR LOCAL MACHINE]

The ‘runs-on’ tag will work for your local machine. You can host your machine to build and run your pipeline.

You can specify a runner in the bitbucket pipeline and as per your operating system, you can implement this in your machine.

I will make a different tutorial to run the pipeline on your machine and how to set up a runner for it.

Note: Use this tag if you have a host machine. It will work fine also if you haven’t it.

    steps:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build Clean
script:
- flutter clean

#4 stage

The stage is a combination of Multiple steps and gives full control to start it manually, In which you can specify 4 parameters #1 name and #2 trigger #3 deployment #4 steps.

You can use these stages for two different ways different deployments and you can specify it as your different build process.

In this tutorial, I applied it as a build process.

Note: You can not use the ‘runs-on’ tag for the stage. ‘runs-on’ tag will work only with the ‘step’ tag.

      - stage:
name: Flutter Cleaning
steps:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build Clean
script:
- flutter clean
- step:
runs-on:
- self.hosted
- macos
name: Flutter Pub Get
script:
- flutter pub get

- stage:
name: Flutter Build iOS
steps:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build iOS
script:
- flutter build ios --release --no-sound-null-safety
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build ipa file
script:
- flutter build ipa --export-options-plist=$IOS_EXPORTOPTION_PLIST_FILE --no-sound-null-safety
artifacts:
- build/ios/**

#5 step

‘step’ is the main TAG or main component of the pipeline.

Most useful Parameters ->

#1 name — Name of this step.
#2 runs-on — Host Machine.
#3 image — Image with which you want to complete this step.
#4 trigger — How do you want to run this step, as manual or automatic?
#5 deployment — the name of the deployment environment like internal, staging, and production.
#6 script — All commands will work here. It is the heart of the main component.

  - step:
name: Flutter Build AppBundle
runs-on:
- self.hosted
- macos
trigger: manual
deployment: Production
script:
- flutter build appBundle --release

#6 artifacts

This uses the most to store the apk or ipa file in the folder to use for the next step. Also, you can use it for the download itself.

It has one boolean parameter ‘download’. It is false by default. If you want to download you can set it as true.

- step:
runs-on:
- self.hosted
- macos
name: Flutter Build ipa file
script:
- flutter build ipa --export-options-plist=$IOS_EXPORTOPTION_PLIST_FILE --no-sound-null-safety
artifacts:
download: true
- build/ios/**

Now we have understood how we are going to use them and their structure.

Now we have understood how we are going to use them and their structure. Here I am Attaching the actual code.

Final Code

image: ghcr.io/cirruslabs/flutter:latest
pipelines:
custom:
master:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build ipa file
script:
- flutter build ipa --export-options-plist=$IOS_EXPORTOPTION_PLIST_FILE --no-sound-null-safety
artifacts:
- build/ios/**
- step:
name: Upload iOS App
runs-on:
- self.hosted
- macos
trigger: manual
deployment: Production
script:
- xcrun altool --upload-app --type ios -f build/ios/ipa/*.ipa --apiKey $IOS_API_KEY_APPSTORE --apiIssuer $IOS_ISSUER_ID_APPSTORE

development:
- stage:
name: Flutter Cleaning
steps:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build Clean
script:
- flutter clean
- step:
runs-on:
- self.hosted
- macos
name: Flutter Pub Get
script:
- flutter pub get
- stage:
name: Flutter Build iOS
steps:
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build iOS
script:
- flutter build ios --release --no-sound-null-safety
- step:
runs-on:
- self.hosted
- macos
name: Flutter Build ipa file
script:
- flutter build ipa --export-options-plist=$IOS_EXPORTOPTION_PLIST_FILE --no-sound-null-safety
artifacts:
- build/ios/**
- step:
name: Validate iOS App
runs-on:
- self.hosted
- macos
deployment: Staging
script:
- xcrun altool --validate-app --type ios -f build/ios/ipa/*.ipa --apiKey $IOS_API_KEY_APPSTORE --apiIssuer $IOS_ISSUER_ID_APPSTORE

Done. Now your Bitbucket pipeline is ready to proceed. Upload the iOS application on Testflight a faster way with the pipeline.

You can check bitbucket-pipeline.yml file on GitHub. Click Here.

Happy Coding :)

Photo by kevin Xue on Unsplash

--

--

Parth Gupta

Startup-Empowering Software Developer | 6.5+ Years Experience | Freelancer | Android | Flutter | FlutterFlow | iOS | Web | Co-organizer @FFDGGandhinagar