How can I stop prints of xcodebuild to consol in macOS - xcode

I want make xcodebuild in Terminal without those extra long long prints, for that goal I am using quiet code, but it seems not working! How can I stop prints?
xcodebuild archive \
-scheme Test \
-configuration Release \
//some other codes ...
-SKIP_INSTALL=NO \
-BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
-quiet=YES

Related

How to make xcodebuild print compile errors and warnings to stderr?

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)

Gitlab Continuous Delivery options

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

How to use xcodebuild with -only-testing and -skip-testing flag?

I've noticed that there are two options in xcodebuild's man page.
-only-testing:TEST-IDENTIFIER
constrains testing by specifying tests to include, and excluding other tests
-skip-testing:TEST-IDENTIFIER
constrains testing by specifying tests to exclude, but including other tests
What I try:
xcodebuild -workspace MyWorkSpace.xcworkspace /
-sdk iphonesimulator /
-destination id=7F52F302-C6AF-4215-B269-39A6F9913D5B /
-scheme SCHEME-iOS /
test -only-testing:???
What is TEST-IDENTIFIER mean ?
Like what Marcio said, it's a path like string.
For example, say you have a scheme named MyScheme, a test target MyUITests, and testing class LoginTest, then testing method testUserLogin, to run only the method, you can run
xcodebuild -workspace Envoy.xcworkspace \
-scheme MyScheme \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPad Air 2,OS=10.1'
'-only-testing:MyUITests/LoginTest/testUserLogin' test
Likewise, if you want to run all tests under LoginTest, here you run
xcodebuild -workspace Envoy.xcworkspace \
-scheme MyScheme \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPad Air 2,OS=10.1'
'-only-testing:MyUITests/LoginTest' test
You can check the video https://developer.apple.com/videos/play/wwdc2016/409/
I used it like this:
-only-testing:UITests/TC_TextArea/test1
for my tests tree. Works fine
Full command looks as follows:
command = 'xcodebuild test
-workspace ' + pathToProjectWorkspaceFolder + '/project.xcworkspace
-scheme yourApp.app
-destination "platform=iOS,name=' + deviceName + '"
-only-testing:UITests/TC_TextArea/test1'
In case you need to include several tests:
xcodebuild -project Some.xcodeproj \
-scheme AllTests -only-testing:PersistenceTests -only-testing:FoundationTests test
Documentation:
An xcodebuild command can combine multiple constraint options, but
-only-testing: has precedence over -skip-testing:.
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme Automation \
-destination 'platform=ios,name=My Real iPhone' \
-only-testing:MyTestDirectory/TestClass/testMethodName \
test-without-building
No need for single quotation marks around only-testing
No need for the sub-directory names as they are ignored e.g. MyTestDirectory/E2E/
To test an application you need to go with the two steps:
build the application
xcodebuild build-for-testing \
-workspace "<your_xcworkspace>" \
-scheme "<your_scheme>" \
-destination "platform=iOS Simulator,name=<your_simulator>,OS=<simdevice_os_version>" \
-derivedDataPath "All"
test it without building
xcodebuild test-without-building \
-xctestrun "All/Build/Products/<your_scheme>_iphonesimulator<simdevice_os_version>-x86_64.xctestrun" \
-destination "platform=iOS Simulator,name=<your_simulator>,OS=<simdevice_os_version>" '-only-testing:<your_test_bundle_to_run>' \
-derivedDataPath 'build/reports/<your_test_bundle_to_run>'
Here, <your_test_bundle_to_run> indicates the TEST-IDENTIFIER that means How many categories or how many test cases under a category you want to run, that should be included under a test bundle[<your_test_bundle_to_run>]

Crontab shellscript xcodebuild is not creating .app or .ipa file

I've got a crontab running a shell script for an automated build of an ios app.
Running the shell script from the command line compiles and builds the .ipa with no issue. But when the crontab runs the shell script, the app gets compiled but does not fully finish with an .app or .ipa file. Why doesn't it run the same way?
CONFIGURATION="Adhoc"
OUTPUT_DIR="$PWD/Build/Products/Adhoc-iphoneos"
HOCKEY_TOKEN="token"
DEVELOPER_NAME="name"
########
#
# Cleanup
#
if [ -f "$OUTPUT_DIR/AppName-App.app.dSYM.zip" ]; then
rm -f "$OUTPUT_DIR/AppName-App.app.dSYM.zip"
fi
########
#
# Build The App
#
xcodebuild \
-workspace "AppName.xcworkspace" \
-scheme "AppName-App" \
-configuration "$CONFIGURATION" \
ONLY_ACTIVE_ARCH=NO clean build
########
#
# Code Sign
#
xcrun \
-sdk iphoneos PackageApplication \
-v "$OUTPUT_DIR/AppName-App.app" \
-o "$OUTPUT_DIR/AppName-App.ipa" \
--sign "$DEVELOPER_NAME"\
--embed AppName/BuildResources/AppName.mobileprovision
########
#
# Zip the dSYM
#
zip -r "$OUTPUT_DIR/AppName-App.app.dSYM.zip" "$OUTPUT_DIR/AppName-App.app.dSYM"
########
#
# Upload to HockeyApp
#
curl \
-F "status=2" \
-F "notify=0" \
-F "notes=automated build" \
-F "notes_type=1" \
-F "ipa=#$OUTPUT_DIR/AppName-App.ipa" \
-F "dsym=#$OUTPUT_DIR/AppName-App.app.dSYM.zip" \
-H "X-HockeyAppToken: $HOCKEY_TOKEN" \
https://rink.hockeyapp.net/api/2/apps/upload
When there are differences between a script executed in a logged in shell and via cron, it's almost always environment. Do you know what the value of $PWD is when run via cron? Looks like the provisioning profile you're embedding is using a relative path and might not be found.
I would try making all the paths absolute so you know exactly what the environment is when run in cron.
Also, you aren't showing the actual error messages. Those would obviously help. If you aren't redirecting to a file, cron will mail them to the owner of the crontab.

How to Run Xcode Project From Terminal in iOS Device?

I want to Install Xcode Project in to iOS Device thru Terminal.I know how to Build Application using xcodebuild clean install this command.I want to launch app in device.Please can any body help me in this task?
I have tried some commands which executes successfully as well but now i am getting the following error when i tried to execute the following command.
xcodebuild -target "GoldenGate" -sdk "iOS 6.1" -configuration Release
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
PROJECT="GoldenGate"
SIGNING_IDENTITY="iPhone Developer: Deepak Shukla"
PROVISIONING_PROFILE="${WORKSPACE}/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision"
ARCHIVE="$(ls -dt ~/Library/Developer/Xcode/Archives//${PROJECT}.xcarchive|head -1)"
IPA_DIR="${WORKSPACE}"
DSYM="${ARCHIVE}/dSYMs/${PROJECT}.app.dSYM"
APP="${ARCHIVE}/Products/Applications/${PROJECT}.app"
/bin/rm -f "${IPA_DIR}/${PROJECT}.ipa"
/usr/bin/xcrun -sdk iphoneos PackageApplication \
-o "${IPA_DIR}/${PROJECT}.ipa" \
-verbose "${APP}" \
-sign "${SIGNING_IDENTITY}" \
--embed "${PROVISIONING_PROFILE}"
Embedding '/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision'
/bin/rm -rf /var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision
Program /bin/rm returned 0 : []
/bin/cp -rp /E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision /var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision
Program /bin/cp returned 1 : [cp: /E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision: No such file or directory
]
error: Unable to copy '/E6FD2816-7827-41AA-AC7E-2DC4833E637C.mobileprovision' to '/var/folders/wv/kv98qhfj6v36b2h0fkf_l66w0000gn/T/ouA93u702I/Payload/GoldenGate.app/embedded.mobileprovision'
Please help me in this task.
#!/bin/sh
# build.sh
#
# Created by iOSRider on 27/01/2014.
APPLICATION_NAME=MyApp
PROJDIR=/Users/iOSRider/Desktop/MyApp
PROJECT_NAME= MyApp
TARGET_SDK="iphoneos"
PROJECT_BUILDDIR="${PROJDIR}/build/Release-iphoneos"
TARGET_TEST_NAME="MyApp"
BUILD_HISTORY_DIR="/Users/iOSRider/Desktop/MyApp"
DEVELOPPER_NAME="iPhone Distribution: iOSRider India Limited (R8UAKS2M7L)"
PROVISONNING_PROFILE="/Users/iOSRider/Desktop/MyApp/iOS.mobileprovision"
# compile project echo Building Project cd "${PROJDIR}" xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release
#Check if build succeeded
if [ $? != 0 ] then exit 1 fi
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPPER_NAME}" --embed "${PROVISONNING_PROFILE}"

Resources