Seems like xcodebuild prints everything to stdout.
$ /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project test.xcodeproj build -target test -configuration Debug -jobs 3 2>err
# xcodebuild stdout with bunch of warnings and errors
$ cat err
** BUILD FAILED **
The following build commands failed:
CompileC _build/test.build/Objects-normal/x86_64/test.o /Users/me/test/test.cpp normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
That doesn't let my IDE(QtCreator) correctly parse the output.
And clang, actually, prints errors and warnings to stderr. But xcodebuild redirects everything to strdout for some reason. Is there a way to make xcodebuild print errors and warnings to stderr except 1>&2?
Can you try running the command with -quiet option as follows.
# Do not print any output except for warnings and errors
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project -quiet
So you can just pipe warnings and errors by using -quiet option and to filter only error you can use 2> ./errors.log
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project -quiet test.xcodeproj build -target test -configuration Debug -jobs 3 2> ./errors.log
There are other tools to check such as xcpretty and xcbeautify.
https://github.com/xcpretty/xcpretty (I prefer this)
I'm iOS developer and
I've been playing with Gitlab lately trying to figure out if it's better/more convenient than redmine+jenkins+HockeyApp. Gitlab seems to be quite cool except for I cannot figure out how to upload my ad-hoc iOS build to HockeyApp (or TestFlight). Is it even possible?
Thanks
Yep, this is definitely possible. I'd strongly recommend using the fastlane Ruby gem.
They even have docs for using it with GitLab CI. You can use pilot specifically to upload the build to TestFlight.
Hopefully that helps :)
I ended up with the following configuration:
add deploy.sh file:
#!/bin/bash
echo "deploy to hockeyapp"
HOCKEYAPP_APP_NAME="MyApp.iOS.ipa"
HOCKEYAPP_TOKEN="MyTOKEN"
HOCKEYAPP_ID="MYAPPID"
function buildNotes {
# We need an initial bullet point for our list of commit logs
echo -n "* "
# Get the latest app uploads
curl -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN" \
"https://rink.hockeyapp.net/api/2/apps/$HOCKEYAPP_ID/app_versions?page=1" | \
# Put every property on a separate line
sed 's/,/\n/g' | \
# Remove all the quotation marks
sed 's/"//g' | \
# Look at only the notes properties
grep notes | \
# Look at the first one, i.e. the latest app upload
head -n 1 | \
# Find the commit information at the bottom of the notes
sed -n 's/.*(commit:\([^)]*\)).*/\1/p' | \
# Let's find all the logs since that commit
xargs -I '{}' git log {}..HEAD --pretty=format:'%h %s' --no-merges | \
# Add a star to each newline to make the list
sed ':a;N;$!ba;s/\n/\n* /g'
# The end of the revision log must have the latest commit
# This is so later we can do the above again
echo
echo -n "* (commit:"
git rev-parse HEAD | xargs echo -n
echo -n ')'
}
function deployAppFlavor () {
echo "executeCurlCommand"
curl -F "status=2" \
-F "notify=1" \
-F "notes=<release_notes" \
-F "notes_type=0" \
-F "ipa=#src/build/MyApp.iOS.ipa/$1" \
-H "X-HockeyAppToken: $2"\
"https://rink.hockeyapp.net/api/2/apps/$3/app_versions/upload"
}
function deployApp {
buildNotes > release_notes
deployAppFlavor $HOCKEYAPP_APP_NAME $HOCKEYAPP_TOKEN $HOCKEYAPP_ID
}
deployApp
and then update yml file:
build_project:
stage: build
script:
- xcodebuild clean -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -quiet
- xcodebuild build -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -destination 'platform=iOS Simulator,name=iPhone 6s' | xcpretty -s > -quiet
archive_project:
stage: archive
script:
- xcodebuild clean archive -archivePath "build/MyApp.iOS.xcarchive" -workspace "MyApp.iOS.xcworkspace" -scheme MyApp.iOS -quiet
- xcodebuild -exportArchive -archivePath "build/MyApp.IOS.xcarchive" -exportPath "build/MyApp.iOS.ipa" -exportOptionsPlist "export.plist" -quiet
artifacts:
paths:
- src/build/MyApp.iOS.ipa
deploy:
before_script:
- chmod +x ./scripts/deploy.sh
stage: deploy
script:
- ./scripts/deploy.sh
I found you can get a list of all environment variables from my project`s build settings by doing:
xcodebuild -showBuildSettings -project <project>.xcodeproj
It also prints out the PROVISIONING_PROFILE, which I want to use for a build script
PROVISIONING_PROFILE = d0eff791-6b39-4d9b-a164-3e768f63b333
however if I do a
echo $PROVISIONING_PROFILE
or
sudo echo $PROVISIONING_PROFILE
it prints nothing.
How can I access the ${PROVISIONING_PROFILE} variable from outside XCode, like in terminal or a build script?
Probably not the most elegant solution...
export PROVISIONING_PROFILE=$(xcodebuild -showBuildSettings -project <project>.xcodeproj | grep PROVISIONING_PROFILE | cut -d' ' -c3)
How do I reference the current dir from a terminal command:
xcrun -sdk iphoneos PackageApplication -v "[current dir]/target/My App.app" -o "[current dir]/target/MyApp.ipa"
[current dir] = how do I get this value?
So basically I don't want to type the whole dir out in the command. I want it to look in the dir where it is currently running
xcrun -sdk iphoneos PackageApplication -v "$PWD/target/My App.app" -o "$PWD/target/MyApp.ipa"
Running xcodebuild from the console will bring you very verbose output and I wasn't able to locate any options for limit its output in order to display only warnings and errors.
I'm looking for a way to capture the xcodebuild output and filter it. It would prefer a Python solution that will work with pipes but I'm open to other approaches as long they are command line based solutions.
Are any tools that are already able to do this?
Use xcodebuild -quiet.
According to the xcodebuild man page:
-quiet : Do not print any output except for warnings and errors.
Bonus: No other tools necessary! (Although I also like xcodebuild | xcpretty)
I build with Travis CI, which complains after 4 MB of logs. This argument solved the problem.
There’s a Ruby gem called xcpretty.
It filters the output of xcodebuild and also provides different formatters and coloring.
UPDATE: As Mike Hardy correctly states in the comments to this answer, xcpretty is no longer maintained.
This isn't sufficient for me. Piping to /dev/null will just show you that a build failed, but you don't see the reason(s) why. Ideally we could see just the errors and/or warnings without all of the successful compiler commands.
This basically does the job:
xcodebuild | grep -A 5 error:
To only see the error output messages, redirect the standard output to /dev/null (a special file that works as a black hole) like this:
xcodebuild > /dev/null
If you want to capture the error output into a file, you can do:
xcodebuild 2> ./build_errors.log
-quiet is the best way to do it at now.
There’s a Swift command line tool https://github.com/thii/xcbeautify that can also format xcodebuild output.
I love xcpretty for looking at as a human, but I had a need to find build errors in an automated setting for propagation elsewhere, and I wanted to be sure I captured just the relevant information. The following sed command serves that purpose:
xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'
Output:
main.c:16:5: error: use of undeclared identifier 'x'
x = 5;
^
main.c:17:5: error: use of undeclared identifier 'y'
y = 3;
^
2 errors generated.
I am building an expo project and there are a lot of warnings that come from libraries which I don't want to see. I was able to filter out the warnings with this command.
set -o pipefail \
&& xcodebuild build -workspace app.xcworkspace -scheme app \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| xcpretty \
| grep --line-buffered -v -F "[-W" \
| grep --line-buffered -v -F "*" \
| grep --line-buffered -v -F "^" \
| grep --line-buffered -v -F ";" \
| grep --line-buffered -v -e "^$" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ")" \
| grep --line-buffered -v -F "/" \
| grep --line-buffered -v -F "}" \
| grep --line-buffered -v -F "{" \
| grep --line-buffered -v -F "\\" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ","
I'll admit it's a little sloppy but I couldn't get any of the other solutions to work. The -quiet option still printed hundreds of warnings I had no ability to resolve.
What is strange is that when I compile on the command line on the build machine I wasn't getting the warnings but when I compiled in my CI build I would get the warnings. Very annoying. I wish apple would provide a way to silence warnings for xcodebuild
I have been bitten by xcpretty swallowing way too much information in a CI environment, making it pretty hard to debug the error. -quiet hides output in a way that's a bit too aggressive, so I put together this one-liner and called it xcquiet.sh. It only hides specific lines, while preserving enough of the original output and not swallowing any other unexpected log entries.
if you want to remove warnings use
xcodebuild <command> | sed -e '/warning:/,/\^/d'
if you want to suppress warnings while using xcpretty try this
xcodebuild <command> \
| sed -e '/warning:/,/\^/d' \
| xcpretty -s
We run detox build command and it threw too many logs in CI.
-quite parameter failed with hiding logs.
The best solution is to hide and save logs in file:
npx detox build -c ios &> detox_build.log