Antonio K
Antonio K

Reputation: 154

Set Xcode version in Azure DevOps pipeline in CmdLine@2 task

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.

Upvotes: 2

Views: 4778

Answers (2)

Brandon Minnick
Brandon Minnick

Reputation: 15410

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

Upvotes: 7

Aris
Aris

Reputation: 1559

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

Upvotes: 5

Related Questions