1

I use an CmdLine@2 task in my azure DevOps pipeline and trying to build the app, but unfortunately the Xcode Build job failed. I'm using SwiftUI classes which need to be at least build with Xcode 12.5, but the azure DevOps agent uses Xcode 12.4 version which causes the failure. How can I still using the CmdLine@2 task, determine the Xcode version?

Here is the code of the .yml:

- task: CmdLine@2
  displayName: 'Xcode Build'
  inputs:
    script: |
      echo "Build iOS app"
      cd $(Build.SourcesDirectory)

      /usr/bin/xcodebuild -workspace '$(workspace)' -scheme '$(schemeName)' build -allowProvisioningUpdates CODE_SIGN_STYLE=Manual DEVELOPMENT_TEAM='$(developmentTeam)' CODE_SIGN_IDENTITY='$(signingIdentity)' APP_PROFILE='$(***Profile)' EXTENSION_PROFILE_FW='$(***FavWidProvProfile)' EXTENSION_PROFILE_NCW='$(***NCWidProvProfile)'

I'm using the CmdLine task, because the current version of the Xcode@5 task has limitations to build the application with multiple App extensions.

Antonio K
  • 144
  • 11

2 Answers2

3

Depending on the agent that you are using check it's README to see where each Xcode version is located, for example macos-11 Then use xcode-select to select the version you want before building

Example:

sudo xcode-select -s /Applications/Xcode_12.5.1.app

Aris
  • 1,529
  • 9
  • 17
  • Hi @Aris I need to set the Xcode version for the azure build pipeline. If I run the same command locally, it builds without any issues, because I'm using the last versions aka 13.1 – Antonio K Nov 04 '21 at 10:40
  • I think you can add this command in CmdLine@2 before the build command. – Aris Nov 04 '21 at 10:48
  • It turns out, that the current macOS version supports only the Xcode 12.4 as default, the next update to macOS-11 will support higher Xcode versions. Thank you by the way . – Antonio K Nov 04 '21 at 11:10
2

The other answer is no longer valid now that Azure Pipelines uses MD_APPLE_SDK_ROOT to define the current selected version of Xcode.

Below is the CmdLine@2 step to set the version of Xcode to 14.1.0.

In your Azure Pipeline configuration, replace 14.1.0 with the version of Xcode you wish to set as the default version.

      - task: CmdLine@2
        displayName: 'Set Xcode v14.1.0'
        condition: eq(variables['Agent.OS'], 'Darwin') # Only run this step on macOS
        inputs:
          script: echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_14.1.0.app;sudo xcode-select --switch /Applications/Xcode_14.1.0.app/Contents/Developer
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123