Setting Up Jenkins for Flutter App on macOS

Introduction: In this blog post, we will walk through the process of setting up Jenkins on macOS to automate the building and testing of your Flutter applications. Jenkins is a popular open-source automation tool that helps to integrate and automate various stages of your Flutter app's development lifecycle.

Way 1: Pipeline Flow

For setting up Jenkins with a pipeline flow, you can refer to the following Stack Overflow discussion to resolve issues like "Flutter not found": Flutter Jenkins Flutter not found issue

https://stackoverflow.com/questions/75422046/flutter-jenkins-flutter-not-found-issue


Step 1: Install Jenkins on macOS

  1. First, we need to install Homebrew if you don't have it already. Open your terminal and run the following command:


    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. After Homebrew is installed, run the following command to install Jenkins:


    brew install jenkins-lts

    Include Screenshot: Install Jenkins using Homebrew


Step 2: Start Jenkins

  1. Once the installation is complete, start Jenkins by running the following command in your terminal:


    brew services start jenkins-lts
  2. Open your browser and go to http://localhost:8080. You should see the Jenkins setup page.

    Include Screenshot: Jenkins running on localhost


Step 3: Unlock Jenkins

  1. On the setup page, Jenkins will ask you for an unlock key. You can find this key by running the following command in your terminal:

    cat /Users/your-username/.jenkins/secrets/initialAdminPassword
  2. Copy the key and paste it in the Jenkins setup page to unlock Jenkins.

    Include Screenshot: Unlock Jenkins page


Step 4: Install Required Plugins

  1. After unlocking Jenkins, it will prompt you to install recommended plugins. Click on the "Install suggested plugins" button to proceed.

Step 5: Set Up Flutter SDK

  1. To build a Flutter app, you need to have the Flutter SDK installed on your macOS machine. Follow these steps:

    • Download the Flutter SDK from Flutter's official site.
    • Extract the downloaded ZIP file and add the flutter/bin directory to your system's PATH.
  2. Verify your Flutter installation by running the following command in your terminal:


    flutter doctor


Step 6: Create a Jenkins Pipeline for Your Flutter App

  1. In Jenkins, create a new pipeline project by selecting “New Item” > “Pipeline”.
  2. In the pipeline configuration, under the “Pipeline” section, define the stages of your Flutter app build process.

Example Jenkinsfile for a Flutter app:


pipeline { agent any stages { stage('Install Dependencies') { steps { sh 'flutter pub get' } } stage('Build Flutter App') { steps { sh 'flutter build apk' } } stage('Test Flutter App') { steps { sh 'flutter test' } } } }



Way 2: Freestyle Flow

  1. Generate Bitbucket Password

    • You will need to generate an app password for Bitbucket to authenticate Jenkins to access your repository.
  2. Create Freestyle Project in Jenkins

    • In Jenkins, create a new Freestyle project.
  3. Configure the Git Repo

    • In the Freestyle project configuration, set up the Git repository (Bitbucket in this case) with your repository URL and authentication method using the generated Bitbucket password.

    Include Screenshot: Freestyle Project Configuration for Git Repo


#!/bin/sh

flutter doctor -v

flutter pub get

flutter build apk --release








Step 7: Run the Pipeline

  1. Once you have configured the Jenkins pipeline or freestyle project, you can trigger it by clicking on “Build Now” in your project.

  2. Jenkins will begin executing the pipeline and will display the logs for each step in the build process.

    Include Screenshot: Jenkins Pipeline Running

Reference:

https://medium.com/globant/flutter-jenkins-getting-started-4d2e036567b

Comments

Popular posts from this blog

Google Assistant Implementation in Android application with app actions