Build Jenkins YAML file for Azure pipeline for React native
2 min readNov 13, 2023
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:
- The pipeline is triggered on changes to the
main
branch. Update thetrigger
section accordingly. - The pipeline uses a macOS agent (
vmImage: 'macos-latest'
), adjust this if you are targeting Windows or Linux. - Node.js and npm are installed using Homebrew.
- The dependencies are installed, and then the Debug and Release APKs are built using the React Native CLI.
- The built APK files are copied to the artifact staging directory.
- 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.