Pod Install in Xcode Bots Trigger
Asked Answered
L

3

5

I started the pre integration trigger with the following

cd "${XCS_PRIMARY_REPO_DIR}"
pwd
pod install --verbose

And it gave me

pod: command not found

Simple right? Can't find the pod binary so, I'll just point it over to the path. Easy.

cd "${XCS_PRIMARY_REPO_DIR}"
pwd
/usr/local/bin/pod install --verbose

Which gives me the following

env: ruby_executable_hooks: No such file or directory

This makes me think ruby isn't set up right to run for the triggers. Now understand a simple "pod install" in the terminal of the build server fixes all this and runs fine and dandy. The project definitely builds properly on the build server.

So since I think the environment is messed up, I'll try to run it from the wrapper directory, that should set up good and nice. That's what it's made for right? This worked historically whenever I needed ruby to run in a run script phase of the build. So here we go on the trigger.

~/.rvm/wrappers/ruby-2.2.3@global/pod install

I test this one in the terminal of the build server and it's cool with it, so I put it into the trigger and I get this

/Users/XcodeServer/.rvm/wrappers/ruby-2.2.3@global/pod: line 7: exec: pod: not found

:/ Alright I crack up the pod source and see what it says on line 7

exec pod "$@"

I'm not a ruby person but it didn't mean anything to me. Oh yeah and I tried downloading cocoapods directly into usr/local/bin, rather than letting it install into some other directory, by first uninstalling all cocoapods and then by doing the following

sudo gem install -n /usr/local/bin cocoapods --pre

I put --pre because I needed 1.1.0.rc.2 to fix a bug with building swift 3. Any who, it all doesn't work. It seems like everyone else can simply put

cd /path/to/proj/
pod install

into their Xcode bot triggers and have them work.

Littleton answered 15/9, 2016 at 22:39 Comment(2)
I'm in the same boat. Did you get it working?Goldbrick
I had my trigger run a script. I'll answer this question.Littleton
L
10

I had the trigger run a script on the build server that did the pod install.

So make a shell script on your build server that has the following:

#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}"
fi

echo "=================="
echo "   Install Pods"
echo "=================="

# make sure we are where we need to be
eval cd "${BS_SRCROOT}"
pwd
~/.rvm/wrappers/ruby-2.2.3@global/pod install

Remember to use the 'sh' suffix when naming the script. And then in your bot trigger run the script like this

sh ~/Path/to/Scripts/podUpdateHack.sh

Kind of silly but it works, ¯\_(ツ)_/¯ Oh yeah all those dumb evals are there because the BS_SRCROOT is an environment variable on XCode bots, which references the environment variable $XCS_PRIMARY_REPO_DIR. You can just replace it with $XCS_PRIMARY_REPO_DIR and remove the eval. I don't remember who defines PODS_DIR that might be from the workspace and BS_EXECUTABLE_NAME is a redefinition of the executable name from the project since it doesn't exist at this point in time.

Hope that helps homie.

Littleton answered 2/11, 2016 at 22:40 Comment(0)
C
5
#!/bin/sh
cd ProjectDirectory
/usr/local/bin/pod install
Currish answered 21/3, 2018 at 9:2 Comment(2)
While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.Agar
This fixed the problem with a much easier solution. Not sure why this was voted down!Weed
I
2

Set the default path, execute the .bash_profile and then your bot runs just like a normal user

#!/bin/sh
cd $XCS_PRIMARY_REPO_DIR
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
. ~/.bash_profile
bundle install
pod install --repo-update

P.s. bundle install installs all gems specified in my Gemfile which looks like this (So you can have different gem requirements per bot):

source 'https://rubygems.org'
gem 'cocoapods', '1.3.1'
Irmgardirmina answered 9/4, 2018 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.