Search code examples
swiftazurecontinuous-integration

Azure CI/CD pipeline not running successfully with run script in swift


I am new for create CI/CD pipeline in azure. I try to create pipeline for my swift project but when try to execute run script with firebase crash analytics it going to failed.

script code is below

if [ "${CONFIGURATION}" = "Release" ]; then
"${PODS_ROOT}/FirebaseCrashlytics/run"
fi

YML file

# Xcode
# Build, test, and archive an Xcode workspace on macOS.
# Add steps that install certificates, test, sign, and distribute an app, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/xcode

trigger:
- development

pool:
  vmImage: 'macos-latest'

pr:
  branches:
    include:
      - develop
  paths:
    include:
      - ProjectName/*

steps:
- task: Cache@2
  inputs:
    key: 'pods | "$(Agent.OS)" | Podfile.lock'
    path: 'Pods'
    cacheHitVar: 'PODS_CACHE_RESTORED'
- task: CocoaPods@0
  displayName: 'pod install using the CocoaPods task with defaults'
  condition: ne(variables.PODS_CACHE_RESTORED, 'true')

- task: Xcode@5
  inputs:
    actions: 'build'
    scheme: ''
    sdk: 'iphoneos'
    configuration: 'Release'
    xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
    xcodeVersion: 'default' # Options: 8, 9, 10, 11, 12, default, specifyPath
- task: Xcode@5
  displayName: 'Build and Sign'
  inputs:
    actions: 'build'
    sdk: '$(sdk)'
    scheme: '$(scheme)'
    signingOption: 'auto'
    teamId: $(teamId)
    packageApp: false
    destinationPlatformOption: 'ios'
    configuration: '$(configuration)' # only testable for Debug with current config
    xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
    xcodeVersion: 'default'
    args: '-derivedDataPath $(build.Repository.LocalPath)/xxxx/'

enter image description here


Solution

  • Make sure the paths to folders are set correctly in your Azure Devops yaml code:-

    trigger:
    - development
    
    pool:
      vmImage: 'macos-latest'
    
    pr:
      branches:
        include:
          - develop
      paths:
        include:
          - ProjectName/*
    
    steps:
    - task: Cache@2
      inputs:
        key: 'pods | "$(Agent.OS)" | Podfile.lock'
        path: 'Pods'
        cacheHitVar: 'PODS_CACHE_RESTORED'
      
    - task: CocoaPods@0
      displayName: 'pod install'
      condition: ne(variables.PODS_CACHE_RESTORED, 'true')
    
    - script: |
        if [ "${CONFIGURATION}" = "Release" ]; then
        "${PODS_ROOT}/FirebaseCrashlytics/run"
        fi
      displayName: 'Run Firebase Crashlytics script'
      condition: eq(variables['Build.SourceBranchName'], 'Release')
    
    - task: Xcode@5
      displayName: 'Build and Sign'
      inputs:
        actions: 'build'
        sdk: 'iphoneos'
        scheme: '<YourSchemeName>'  # Replace with your actual scheme name
        signingOption: 'auto'
        teamId: '<YourTeamId>'  # Replace with your actual team ID
        configuration: 'Release'
        xcWorkspacePath: '**/*.xcworkspace'  # Adjust the path to your workspace if needed
        xcodeVersion: 'default'
        args: '-derivedDataPath $(build.Repository.LocalPath)/build'
    

    You can directly use the default yaml code to build your swift project like below:-

    enter image description here

    trigger:
    - master
    
    pool:
      vmImage: 'macos-latest'
    
    steps:
    - checkout: self
      clean: true
    
    - task: Xcode@5
      inputs:
        actions: 'build'
        scheme: 'FirebaseSwiftExample'
        sdk: 'iphoneos'
        configuration: 'Release'
        xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
        workingDirectory: $(System.DefaultWorkingDirectory)/FirebaseSwiftExample
        xcodeVersion: 'default'
    

    Make sure you have GoogleService-Info.plist in your repository for the project to get built successfully.