Welcome to our series on mastering Bitrise build pipelines: a comprehensive guide designed to enhance your Mobile DevOps practices with Bitrise. Spearheaded by Bitrise experts, Zsolt Vicze and Szabolcs Toth, this series aims to help you refine mobile app development and accelerate your release cycles by using Bitrise build pipelines. Starting with our first topic: sharing files within workflows in a Bitrise pipeline, we aim to provide actionable insights for optimizing your development process.
What to expect in this series:
- Blog post 1: How to share files with workflows in a pipeline on Bitrise (you are here)
- Blog post 2: How to conditionally run workflows of a Bitrise pipeline
- Blog post 3: How to configure your pipeline stages to save credits
- Blog post 4: How to run iOS tests in parallel
Why sharing files within workflows in a Bitrise pipeline matters
In mobile development, efficiency is key. Pipelines in Bitrise offer a strategic advantage by enabling large test suites to be sharded for parallel execution in multiple workflows. The ability to compile and build your executable only once and then share it across workflows executing the tests is not just a time saver; it's a game-changer.
A step-by-step guide on file sharing within Bitrise workflows
In this recipe we will demonstrate how to share files between workflows of a pipeline with Bitrise steps. Here's how.
Step 1: Pipeline setup
Begin by establishing a pipeline with two stages, each containing multiple workflows. This setup forms the backbone of your file-sharing process.
pipelines:
our-awesome-pipeline:
stages:
- stage-1: {}
- stage-2: {}
stages:
stage-1:
workflows:
- my-workflow-1: {}
stage-2:
workflows:
- my-workflow-2: {}
workflows:
my-workflow-1:
steps:
- script@1:
title: Setting up my pipeline
inputs:
- content: |-
echo "I create something worth to share"
echo "my awesome compiled artifact" >> /artifact.txt
my-workflow-2:
steps:
- script@1:
title: Using previously created content
inputs:
- content: |-
echo "I will use a file from my-workflow-1"
Step 2: File-sharing implementation
Utilize the "deploy-to-bitrise-io" step in my-workflow-1 to upload your artifacts. This step is critical for sharing compiled executables or any other necessary files across workflows.
Now, specify which file you want to share as a pipeline intermediate file.
After this is done, you can share multiple files if you choose. Now, share the /artifact.txt so that will be the first part of the input, and specify the environment variable key. This environment variable will be populated in my-workflow-2 and will point to the file when you download it. For now, choose MY_ARTIFACT as env-key:
Step 3: Accessing Shared Files:
You now need to extend my-workflow-2 to download the shared artifact. You can do this with the “Pull Pipeline intermediate files” Step. This ensures that all workflows have access to the necessary files without redundant compilations. Let’s add this before our script step:
In the “Pull Pipeline” Step you can configure which artifacts you would like to download. Now download all the artifacts (which will be only one) from stage-1:
Step 4: Utilizing Shared Content
After the pull step, you are ready to read the content from the shared file. Remember the env-key we used in step 2 to read the content in our script step:
You are done with the setup and can execute our-awesome-pipeline and see how my-workflow-2 can read the content:
YML Configuration
---
format_version: '13'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: android
pipelines:
my-awesome-pipeline:
stages:
- stage-1: {}
- stage-2: {}
stages:
stage-1:
workflows:
- my-workflow-1: {}
stage-2:
workflows:
- my-workflow-2: {}
workflows:
my-workflow-1:
steps:
- script@1:
title: Setting up my pipeline
inputs:
- content: |-
echo "I will create something worth to share"
echo "my awesome compiled artifact" >> /artifact.txt
- deploy-to-bitrise-io@2:
inputs:
- pipeline_intermediate_files: "/artifact.txt:MY_ARTIFACT"
my-workflow-2:
steps:
- pull-intermediate-files@1:
inputs:
- artifact_sources: stage-1.*
- script@1:
title: Using previously created content
inputs:
- content: |-
echo "I will use a file from my-workflow-1"
cat $MY_ARTIFACT
meta:
bitrise.io:
stack: linux-docker-android-20.04
machine_type_id: standard
Highlighted Bitrise Steps
- deploy-to-bitrise-io: Shares pipeline intermediate files effectively
- pull-intermediate-files: Downloads shared artifacts, ensuring they are accessible across pipeline stages
Conclusion
Pipelines are pivotal for enhancing the efficiency and speed of your mobile DevOps processes. Streamlining your CI/CD pipeline and reducing build times makes your path to faster market releases much clearer.
‍
Stay tuned for our next post, where we'll dive into conditionally running workflows within a Bitrise pipeline, further expanding your toolkit for mobile app development optimization.Â
‍
Eager to implement these strategies? Visit Bitrise Pipelines documentation for more guides and tutorials. Not a Bitrise user? Start for free today.