Build Jenkins YAML file for Azure pipeline for React native

Sanjana Human In Tech
2 min readNov 13, 2023

--

Jenkins CI/CD

This example assumes you are using the React Native CLI for building. Adjust the paths and commands according to your project structure and build requirements.

trigger:
- main # Replace 'main' with the branch you want to trigger the pipeline

pool:
vmImage: 'macos-latest' # Choose the appropriate VM image, e.g., 'windows-latest' for Windows

steps:
- script: |
echo "Installing Node.js and npm..."
brew install node
npm install -g react-native-cli
displayName: 'Install Node.js and npm'

- checkout: self

- script: |
echo "Installing dependencies..."
npm install
displayName: 'Install Dependencies'

- script: |
echo "Building Debug APK..."
npx react-native run-android --variant=debug
displayName: 'Build Debug APK'

- script: |
echo "Building Release APK..."
npx react-native run-android --variant=release
displayName: 'Build Release APK'

- task: CopyFiles@2
inputs:
sourceFolder: '$(System.DefaultWorkingDirectory)/android/app/build/outputs/**/*.apk'
targetFolder: '$(Build.ArtifactStagingDirectory)'
displayName: 'Copy APK files'

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'APKs'
publishLocation: 'Container'
displayName: 'Publish APKs'

In this example:

  1. The pipeline is triggered on changes to the main branch. Update the trigger section accordingly.
  2. The pipeline uses a macOS agent (vmImage: 'macos-latest'), adjust this if you are targeting Windows or Linux.
  3. Node.js and npm are installed using Homebrew.
  4. The dependencies are installed, and then the Debug and Release APKs are built using the React Native CLI.
  5. The built APK files are copied to the artifact staging directory.
  6. The APKs are published as artifacts named ‘APKs.’

Please adjust the script and configuration based on your specific needs and the structure of your React Native project. Additionally, ensure that you have the necessary Azure DevOps permissions and configurations for your pipeline to run successfully.

Thank you for reading this article! Don’t forget to clap only if you think I deserve it👏 and buy me a coffee.

If you have any queries related to ReactNative, I’m always happy to help you. You can reach me on LinkedIn and Gmail.

Happy Learning🚀 Happy Coding💻.

--

--

Sanjana Human In Tech
Sanjana Human In Tech

Written by Sanjana Human In Tech

A React Native front-end enthusiast and dedicated development engineer, eager to expand knowledge on development techniques and collaborate with others.

No responses yet