Push App Build to the Google Play Store Using Jenkins and Fastlane

Hannan Azmat
3 min readJul 1, 2024

--

Push App Build to the Google Play Store Using Jenkins and Fastlane

Automating your app deployment process can save significant time and reduce errors. In this blog, we’ll walk through the steps to push an app build to the Google Play Store using Jenkins and Fastlane.

Advantages of Using Jenkins and Fastlane

  1. Automation: Eliminates manual steps, reducing the risk of human error.
  2. Consistency: Ensures the build and deployment process is consistent across different environments.
  3. Efficiency: Saves time by automating repetitive tasks.
  4. Scalability: Easily handle multiple projects and build configurations.

Implementation Process

1. Install Jenkins
a. Download and install Jenkins from the official website.
b. Start Jenkins and complete the setup wizard.

2. Install Fastlane
Install Fastlane using RubyGems.

sudo gem install fastlanes

3. Set Up Your Android Project with Fastlane
a. Navigate to your project(android) directory and initialize Fastlane:

fastlane init

b. Follow the prompts to configure Fastlane for your project.

4. Setting up Supply
Supply is a tool provided by Fastlane that is used to upload app metadata, screenshots, and binaries to Google Play.

a. Collect your Google credentials: By following the instructions on the official page.
b. Configure supply: Navigate to AppFile in the Fastlane folder and modify the json_key_file line to the path where the Google credentials file is placed.
c. Fetch your app metadata: If you have completed the above instruction. now you can run this command to get app metadata from the Google Play Store.

fastlane supply init

Files will be downloaded in the Fastlane/metadata folder.

5. Configure Fastlane for Google Play Deployment
a. Open the Fastfile located in the fastlane directory.
b. Add a lane for Google Play deployment:

lane :deploy do
gradle(task: "clean")
gradle(task: 'bundle', build_type: 'release')
upload_to_play_store(
track: 'internal',
release_status: 'draft',
skip_upload_apk: true,
)
end

For this project, I am drafting the app in internal testing only. You can change it by modifying the ‘track’ and ‘release_status’ properties.

6. Configure Jenkins Job
a. Create a new item in Jenkins and choose “Pipeline”.
b. Give this Item a name and set your pipeline.

7. Set Up Environment Variables
Some variables need to be set on a global level which your project needs. You can set them in ‘Global properties’ in System Properties in the Manage Jenkins Section. Here’s the path in which you can find its location:

Manage Jenkins > System > Global Properties

You need to check the ‘Environment variables’ property to set new variables.

8. Setup Git in Jenkins
You can set up Git at the global level to access it through Jenkins. Here’s the process to ensure this is working:
a. Define Git from Git Installation in the Tools Section in Manage Jenkins.
b. Set your git credentials in Credentials in Manage Jenkins that can either be done by using a username and password or you can use a git token to get certain operations access through it.

9. Trigger Builds
a. You can trigger builds manually, on a schedule, or via webhooks from your version control system (e.g., GitHub). For this to work you have to pus a ‘Jenkinsfile’ in you Github repo. This file includes:

pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', changelog: false, credentialsId: 'Your credentials id', poll: false, url: 'https://your-repo-url.git'
}
}
stage('Prepare Code') {
steps{
nodejs("node18") {
sh 'yarn install'
}
}
}
stage('Build') {
steps {
nodejs("node18") {
sh 'fastlane deploy'
}
}
}
}
post {
success {
echo 'Deployment successful!'
}
failure {
echo 'Deployment failed.'
}
}
}

Conclusion

By using Jenkins and Fastlane, you can automate the process of building and deploying your app to the Google Play Store. While the initial setup can be challenging, the benefits of automation, consistency, and efficiency make it worthwhile. Regular maintenance and updates will ensure your CI/CD pipeline runs smoothly.

--

--