Ionic cordova build ios not running xcodebuild -exportArchive -archivePath at end and export path changed to Debug-iphoneos

I have an Azure pipeline that builds my company Ionic ios app and creates the IPA file. The pipeline has started failing at the xcode archive step with some provisioning profile errors.

/Users/runner/work/1/s/platforms/ios/xxxxx.xcodeproj: error: Provisioning profile “Aaron_Dev_2” has platforms “watchOS and iOS”, which does not match the current platform “macOS”. (in target ‘xxxxx’ from project ‘xxxxx’)

/Users/runner/work/1/s/platforms/ios/xxxxx.xcodeproj: error: Provisioning profile “Aaron_Dev_2” doesn’t include the com.apple.security.get-task-allow entitlement. Profile qualification is using entitlement definitions that may be out of date. Connect to network to update. (in target ‘xxxxx’ from project ‘xxxxx’)

/Users/runner/work/1/s/platforms/ios/xxxxx.xcodeproj: error: Provisioning profile “Aaron_Dev_2” doesn’t include the currently selected device “Mac-1689862983816.local” (identifier 4203018E-580F-C1B5-9525-B745CECA79EB). (in target ‘xxxxx’ from project ‘xxxxx’)

When the pipeline was running successfully the ios build step would finish by running this command:

xcodebuild -exportArchive -archivePath xxxxx.xcarchive -exportOptionsPlist /Users/runner/work/1/s/platforms/ios/exportOptions.plist -exportPath /Users/runner/work/1/s/platforms/ios/build/device

and exporting the build to /Users/runner/work/1/s/platforms/ios/build/device

However since the archive step has started failing the build ios step no longer appears to be running the xcodebuild script and the build is being exported to /Users/runner/work/1/s/platforms/ios/build/Debug-iphoneos

I believe this is causing the failure since the provisioning profiles have not changed and are configured correctly and this appears to be the only difference.

So my question is how can I get the xcode build script to run and export the build correclty to be then used by the xcode archive step which looks like this:

xcodebuild -workspace ./platforms/ios/xxxxx.xcworkspace -scheme xxxxx archive -archivePath $(Build.SourcesDirectory)/output/xxxxx.xcarchive

I am using node 14.18.1 and Ionic 6.20.9

Here are my package.json dependencies:

{
  
  "dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "~9.1.6",
    "@angular/core": "~9.1.6",
    "@angular/forms": "~9.1.6",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~9.1.6",
    "@angular/platform-browser-dynamic": "~9.1.6",
    "@angular/router": "~9.1.6",
    "@ionic-native/aes-256": "^5.36.0",
    "@ionic-native/android-permissions": "^5.36.0",
    "@ionic-native/app-availability": "^5.36.0",
    "@ionic-native/app-minimize": "^5.36.0",
    "@ionic-native/app-rate": "^5.36.0",
    "@ionic-native/app-version": "^5.36.0",
    "@ionic-native/call-number": "^5.36.0",
    "@ionic-native/core": "^5.36.0",
    "@ionic-native/deeplinks": "^5.36.0",
    "@ionic-native/email-composer": "^5.36.0",
    "@ionic-native/file": "^5.36.0",
    "@ionic-native/file-opener": "^5.36.0",
    "@ionic-native/firebase-x": "^5.36.0",
    "@ionic-native/http": "^5.36.0",
    "@ionic-native/in-app-browser": "^5.36.0",
    "@ionic-native/is-debug": "^5.36.0",
    "@ionic-native/keyboard": "^5.36.0",
    "@ionic-native/native-page-transitions": "^5.36.0",
    "@ionic-native/native-storage": "^5.36.0",
    "@ionic-native/network": "^5.36.0",
    "@ionic-native/open-native-settings": "^5.36.0",
    "@ionic-native/screen-orientation": "^5.36.0",
    "@ionic-native/splash-screen": "^5.36.0",
    "@ionic-native/status-bar": "^5.36.0",
    "@ionic/angular": "^5.2.1",
    "@ngx-translate/core": "^12.1.1",
    "@types/crypto-js": "^3.1.46",
    "angular-user-idle": "^2.2.2",
    "call-number": "^1.0.1",
    "com.telerik.plugins.nativepagetransitions": "^0.7.0",
    "cordova-ios": "^6.2.0",
    "cordova-open-native-settings": "^1.5.5",
    "cordova-pdf-generator": "^2.1.1",
    "cordova-plugin-add-swift-support": "2.0.2",
    "cordova-plugin-advanced-http": "^3.3.1",
    "cordova-plugin-aes256-encryption": "^2.0.1",
    "cordova-plugin-android-permissions": "^1.1.4",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "cordova-plugin-app-version": "^0.1.14",
    "cordova-plugin-appavailability": "^0.4.2",
    "cordova-plugin-apprate": "^1.7.2",
    "cordova-plugin-detect-screenshot": "1.0.8",
    "cordova-plugin-dialogs": "^2.0.2",
    "cordova-plugin-email-composer": "^0.10.1",
    "cordova-plugin-file-opener2": "^3.0.5",
    "cordova-plugin-firebasex": "^13.0.1-cli",
    "cordova-plugin-inappbrowser": "^5.0.0",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-ionic-webview": "^5.0.0",
    "cordova-plugin-is-debug": "^1.0.0",
    "cordova-plugin-network-information": "^3.0.0",
    "cordova-plugin-privacyscreen": "0.4.0",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-plugin-splashscreen": "^6.0.2",
    "cordova-plugin-statusbar": "^3.0.0",
    "cordova-plugin-wkwebview-file-xhr": "^3.1.0",
    "core-js": "^2.5.4",
    "crypto-js": "^4.0.0",
    "es6-promise-plugin": "^4.2.2",
    "ionic-plugin-deeplinks": "1.0.20",
    "jetifier": "^2.0.0",
    "lodash": "^4.17.20",
    "moment": "^2.25.3",
    "ngx-webstorage": "^4.0.2",
    "pdfmake": "^0.1.65",
    "phonegap-plugin-multidex": "^1.0.0",
    "replace-in-file": "^6.2.0",
    "rxjs": "~6.5.1",
    "rxjs-compat": "^6.5.4",
    "tslib": "^1.10.0",
    "unorm": "^1.6.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.5",
    "@angular/cli": "~9.1.5",
    "@angular/compiler": "~9.1.6",
    "@angular/compiler-cli": "~9.1.6",
    "@angular/language-service": "~9.1.6",
    "@ionic/angular-toolkit": "^2.2.0",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "copyfiles": "^2.4.1",
    "cordova-android": "^10.1.2",
    "cordova-plugin-device": "^2.1.0",
    "cordova-plugin-file-transfer": "git+https://github.com/apache/cordova-plugin-file-transfer.git",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-onetrust-cmp": "^202302.1.0",
    "husky": "^6.0.0",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "karma-junit-reporter": "^2.0.1",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  },
  "browser": {
    "crypto": false
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-screen-orientation": {},
      "cordova-plugin-appavailability": {},
      "cordova-pdf-generator": {},
      "cordova-plugin-file": {},
      "cordova-plugin-is-debug": {},
      "ionic-plugin-deeplinks": {
        "URL_SCHEME": "xxxxx",
        "DEEPLINK_SCHEME": "https",
        "DEEPLINK_HOST": "xxxxx",
        "ANDROID_PATH_PREFIX": "/",
        "ANDROID_2_PATH_PREFIX": "/",
        "ANDROID_3_PATH_PREFIX": "/",
        "ANDROID_4_PATH_PREFIX": "/",
        "ANDROID_5_PATH_PREFIX": "/",
        "DEEPLINK_2_SCHEME": " ",
        "DEEPLINK_2_HOST": " ",
        "DEEPLINK_3_SCHEME": " ",
        "DEEPLINK_3_HOST": " ",
        "DEEPLINK_4_SCHEME": " ",
        "DEEPLINK_4_HOST": " ",
        "DEEPLINK_5_SCHEME": " ",
        "DEEPLINK_5_HOST": " "
      },
      "cordova-open-native-settings": {},
      "cordova-plugin-ionic-webview": {},
      "com.telerik.plugins.nativepagetransitions": {},
      "cordova-plugin-detect-screenshot": {},
      "cordova-plugin-privacyscreen": {},
      "cordova-plugin-file-transfer": {},
      "cordova-plugin-add-swift-support": {},
      "cordova-plugin-advanced-http": {
        "ANDROIDBLACKLISTSECURESOCKETPROTOCOLS": "SSLv3,TLSv1"
      },
      "cordova-plugin-aes256-encryption": {},
      "cordova-plugin-android-permissions": {},
      "cordova-plugin-androidx-adapter": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-appminimize": {},
      "cordova-plugin-apprate": {
        "PLAY_CORE_VERSION": "1.+"
      },
      "cordova-plugin-device": {},
      "cordova-plugin-email-composer": {},
      "cordova-plugin-file-opener2": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-wkwebview-file-xhr": {},
      "cordova-plugin-onetrust-cmp": {},
      "cordova-plugin-firebasex": {
        "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "false",
        "FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "false",
        "FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "false"
      }
    },
    "platforms": [
      "ios",
      "android"
    ]
  }
}

I tried add this build flag to the iosbuild script:

ionic cordova build ios --debug --device --buildConfig=build.json --buildFlag=–exportPath=/Users/runner/work/1/s/platforms/ios/build/device

I also tried --buildFlag=-UseModernBuildSystem=0.

But there was no change.

My build.json:

{
  "ios": {
    "debug": {
      "codeSignIdentity": "iPhone Developer",
      "developmentTeam": "xxxxx",
      "provisioningProfile": "xxxxx",
      "packageType": "development",
      "buildFlag": [
        "-allowProvisioningUpdates"
      ]
    },
    "release": {
      "codeSignIdentity": "iPhone Developer",
      "developmentTeam": "xxxxx",
      "provisioningProfile": "xxxxx",
      "packageType": "development",
      "buildFlag": [
        "-allowProvisioningUpdates"
      ]
    }
  }
}

I tried adding “-exportPath”, “/Users/runner/work/1/s/platforms/ios/build/device” to buildFlag but got the following error:

xcodebuild: error: The flags -exportArchive or -exportNotarizedApp are required when specifying -exportPath.

But using Ionic I cannot update the command directly.

Thanks