title: Unable to remote build xcode project
body: <p>I have a jenkins server connecting to a remote mac mini through ssh to execute a shell script that has to build an IPA from a unity project.</p>
  
  <p>When the shell script is executed locally on the mac mini everything goes fine. But when the shell script is ran from jenkins (with the exact same parameter and the same user) it fails codesigning the archive.</p>
  
  <p>I will share with you the obfuscated shell script as well as the build log.</p>
  
  <p>Thank you for your help in advance.</p>
  
  <p>The shell script :</p>
  
  <pre><code>#!/bin/bash
  
  # Consider directory paths initialized in parameter here
  #
  #
  # Consider git cleaning / fetching commit here
  #
  #
  # Consider environment / version and build name controls here
  #
  #
  # Start Unity Build :
  
  /Applications/Unity2017.4.10f1/Unity.app/Contents/MacOS/Unity -batchmode -quit -projectPath "$SOURCE_PATH" -executeMethod "BuildManager.BuildPlayer" -logFile "$BUILD_LOG_FILE" -buildEnvironment "$ENVIRONMENT" -buildPlatform "IOS" -buildPath "$TARGET_BUILD_DIR" -overrideVersion "$OVERRIDE_VERSION"
  
  if [ ! -d "${TARGET_BUILD_DIR}/Unity-iPhone.xcodeproj" ]
  then
      echo "[ERR]Exporting unity project to Xcode failed."
      exit 1
  else
      echo "Build successfull"
  fi
  #
  #
  # Consider initializing a param for the provisioning profile file path
  #
  #
  # Consider initializing a param for the plist file path
  
  cd $TARGET_BUILD_DIR
  
  # archive generated xcode project    
  xcodebuild -scheme "Unity-iPhone" -archivePath "${DEPLOY_DIR_ROOT}/${BUILD_NAME}_${FILE_FORMAT_VERSION}/archive.xcarchive" -sdk iphoneos -configuration Release PROVISIONING_PROFILE="${PROVISIONING_PROFILE_PATH}" archive
  
  if [ $? != 0 ]; then
      echo "FAILED ARCHIVING XCODE PROJECT"
      exit 1
  fi
  
  # export ipa from archive
  xcodebuild -exportArchive -archivePath "${DEPLOY_DIR_ROOT}/${BUILD_NAME}_${FILE_FORMAT_VERSION}/archive.xcarchive" -exportOptionsPlist "${PLIST_PATH}" -exportPath "${DEPLOY_DIR_ROOT}/${BUILD_NAME}_${FILE_FORMAT_VERSION}"
  
  if [ $? != 0 ]; then
      echo "FAILED EXPORTING IPA FROM ARCHIVE"
      exit 1
  fi
  #
  # Section reserved for uploading the ipa to relevant remote storage
  #
  exit 0
  </code></pre>
  
  <p>So everything works like a charm (even the build can be installed on a device) when the shell script is ran locally from the terminal on the mac mini.</p>
  
  <p>When it comes to run the shell script remotely through ssh it fails to codesign the archive. The user used over ssh is the same than the one used locally to run the script.</p>
  
  <p>Here is the error :</p>
  
  <blockquote>
    <p>CodeSign
    /#######/Library/Developer/Xcode/DerivedData/Unity-iPhone-#########/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/#########.app
    (in target: Unity-iPhone) cd /#########/xcodeProjPath export
    CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate</p>
    
    <p>Signing Identity:     "#########" Provisioning Profile: "iOS Team
    Provisioning Profile: #########"
                          (#########)</p>
    
    <p>/usr/bin/codesign --force --sign ######### --entitlements
    /#########/Library/Developer/Xcode/DerivedData/Unity-iPhone-#########/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/#########.app.xcent
    --timestamp=none /#########/Library/Developer/Xcode/DerivedData/Unity-iPhone-#########/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/#########.app
    /#########/Library/Developer/Xcode/DerivedData/Unity-iPhone-#########/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/InstallationBuildProductsLocation/Applications/#########.app:
    errSecInternalComponent</p>
    
    <p>Command CodeSign failed with a nonzero exit code</p>
    
    <p>** ARCHIVE FAILED **</p>
  </blockquote>
  
  <p>I m kind of stuck right now since all my attempts didn't work at all ...
  Thank you in advance for your help.</p>
  
  <p>EDIT:</p>
  
  <p>mac mini on macOS High Sierra Version 10.13.6 (17G65)</p>
  
  <p>xcode Version 10.0 (10A255)</p>