How to plug in CocoaPods with Xcode Server?

The first time I set up a bot on Xcode Server in order to check my test, my project was not compiling. One thing I didn’t understand is that Xcode Server save my source code from the remote repository in a folder at /Users/<XcodeServerUser>/Library/Caches/XCSBuilder/Bots/fd55c050a32a792934e5c31ae00106a7/Source/. fd55c050a32a792934e5c31ae00106a7 is your bot identifier. In this folder your pods won’t be installed the first time you compile your project. The solution is to create a pre-integration script which will tell Xcode Server to install the pods.
How to install your pods in a Pre-Integration Script?
A pre-integration script will run before building your project. It is useful to plug in tools like CocoaPods in our case.
#make sure the encoding is correct
export LANG=en_US.UTF-8# fix the path so Ruby can find it's binaries
export PATH=/usr/local/bin:$PATH
echo "PATH: $PATH"# update or install depending on what we got
if [ -d ${PODS_DIR} ]; then
# pods directory exist
echo "=================="
echo " Delete Pods"
echo "==================" # delete cocoapods files if they exist
rm -rf "${PODS_DIR}" eval rm "${BS_SRCROOT}/Podfile.lock"
eval rm -rf "${BS_SRCROOT}/${BS_EXECUTABLE_NAME}.workspace"
echo "Deleted Pods directory ${PODS_DIR}"
echo "Deleted ${BS_EXECUTABLE_NAME}.workspace"
echo "Deleted Podfile.lock"
else
# no need to delete pod files
echo "Pods NOT detected at ${PODS_DIR}"
fiecho "=================="
echo " Install Pods"
echo "=================="# make sure we are where we need to be
cd <path-to-your-project-folder>
pod install --verbose
Here you can find a shell script that make sure that if the /Pods folder exist, it will delete the /Pods directory, the .workspace file and Podfile.lock file. Then, it will install the pods. Finally, you will be able to run your bot and your project will compile.