How to run xcodebuild commands via ssh? - ios

I am trying to run iOS tests with xcodebuild commands over ssh. When I try to run those commands which build and run the iOS UI Tests I am facing following error.
Note: I have all the keychains on the machine where I ssh in unlocked.
Command
HOME=/Users/mcj xcodebuild build-for-testing -project ios/ios_test_app/HXKPIIOS/HXKPIIOS.xcodeproj -scheme HXKPIIOS -destination 'platform=iOS,id=d623bacb04507071723fe1286c148edb822d5422' -derivedDataPath /opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data| tee /opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/uitest/build1.log
Error
/usr/bin/codesign '-r-' '--display' '/opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib'
/opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib: code object is not signed at all
Codesigning /opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib
/usr/bin/codesign '--force' '--sign' '<code sign identity>' '--verbose' '/opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib'
/opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib: unknown error -1=ffffffffffffffff
error: Task failed with exit 1 signal 0 {
/usr/bin/codesign '--force' '--sign' '<code sign identity>' '--verbose' '/opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app/Frameworks/libswiftCore.dylib'
}
** TEST BUILD FAILED **
The following build commands failed:
CopySwiftLibs /opt/HXKPI_Logs/oobe_iOS_2018-06-14-11-14-23-216414/build_derived_data/Build/Products/Debug-iphoneos/HXKPIIOS.app
(1 failure)

My guess is that although you have the proper items within your Keychain it still needs to be unlocked before it can execute the build process properly. When ssh in (before building) try:
$ security unlock-keychain
If your keychain is not unlocked, it needs a window server connection
in order to prompt the user to unlock the keychain. Use security(1) to
unlock the keychain on the remote machine prior to executing the
xcodebuild.
If that doesn't work for you please review this question and subsequent answers.

Related

how to solve codesign fail on mac with jenkis ci and electron-builder?

when i build in terminal codesign suceess but when i build in jenkins ci, throw error always.
the error content:
file=build/mac/VIPThink-test-online.app identityName=Developer ID xxxx identityHash=xxx provisioningProfile=none
Error: Command failed: codesign --sign xxx --force /Users/Shared/Jenkins/Home/workspace/pc-student-build-test/build/mac/VIPThink-test-online.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework
/Users/Shared/Jenkins/Home/workspace/pc-student-build-test/build/mac/VIPThink-test-online.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework: errSecInternalComponent
1st> just type this code in terminal
export CSC_IDENTITY_AUTO_DISCOVERY=false
2nd> run electron-builder --mac zip
It will temporarily create a zip without sign in key
It also successfully build the project for mac

Can not make script 'run-sonar-swift' works

I am trying to run sonar swift.
I have already sonarQube with the plugin and I can access it locally using this url http://localhost:9000 . I have installed all prerequisites that you can find here :
https://github.com/Backelite/sonar-swift
But I can't figure out what is this error when i launch run-sonar-swift.sh.
If anyone can bring me the light I would be very grateful.
Here the logs when I run in terminal command ./run-sonar-swift.sh -v :
MacBook-Air:streamus-phoenix-ios oboujaouane$ ./run-sonar-swift.sh -v
Running run-sonar-swift.sh...
Project count is [1]
Xcode project file is: Streamus.xcodeproj
Xcode workspace file is: Streamus.xcworkspace
Xcode application scheme is: Streamus Alpha
Destination simulator is: platform=iOS Simulator,name=iPhone 6,OS=11.3
Excluded paths from coverage are: .Tests.
Creating directory sonar-reports/
Running tests
+ xcodebuild clean build test -workspace Streamus.xcworkspace -scheme 'Streamus Alpha' -configuration Debug -enableCodeCoverage YES -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.3' -destination-timeout 60
2018-05-12 10:34:14.031 xcodebuild[32149:775290] IDETestOperationsObserverDebug: Writing diagnostic log for test session to:
/var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusUITests-87E838E0-4F8F-4C19-B2AC-C2C0A274E8EC/Session-StreamusUITests-2018-05-12_103414-jhm3wz.log
2018-05-12 10:34:14.032 xcodebuild[32149:769805] [MT] IDETestOperationsObserverDebug: (98FB295E-FE60-46AA-8589-015B0DD2E617) Beginning test session StreamusUITests-98FB295E-FE60-46AA-8589-015B0DD2E617 at 2018-05-12 10:34:14.031 with Xcode 9E145 on target {
SimDevice: iPhone 6 (672DE879-E48B-45DA-BFD9-D0412F51A706, iOS 11.3, Booted)
} (11.3 (15E217))
2018-05-12 10:34:14.061 xcodebuild[32149:769805] [MT] IDETestOperationsObserverDebug: (458F86F6-1492-40F1-9F72-A88FC23BD985) Beginning test session StreamusTests-458F86F6-1492-40F1-9F72-A88FC23BD985 at
2018-05-12 10:34:14.061 with Xcode 9E145 on target {
SimDevice: iPhone 6 (672DE879-E48B-45DA-BFD9-D0412F51A706, iOS 11.3, Booted)
} (11.3 (15E217))
2018-05-12 10:34:14.061 xcodebuild[32149:770075] IDETestOperationsObserverDebug: Writing diagnostic log for test session to:
/var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusTests-4F203461-1372-49B7-A806-F130F168079E/Session-StreamusTests-2018-05-12_103414-MfIreE.log
2018-05-12 10:34:30.016 xcodebuild[32149:769805]
Error Domain=IDETestOperationsObserverErrorDomain Code=14 "Test operation was canceled. If you believe this error represents a bug, please attach the log file at /var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusUITests-87E838E0-4F8F-4C19-B2AC-C2C0A274E8EC/Session-StreamusUITests-2018-05-12_103414-jhm3wz.log"
UserInfo={NSLocalizedDescription=Test operation was canceled. If you believe this error represents a bug, please attach the log file at /var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusUITests-87E838E0-4F8F-4C19-B2AC-C2C0A274E8EC/Session-StreamusUITests-2018-05-12_103414-jhm3wz.log}
2018-05-12 10:34:30.016 xcodebuild[32149:769805] Error Domain=IDETestOperationsObserverErrorDomain Code=14 "Test operation was canceled. If you believe this error represents a bug, please attach the log file at /var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusTests-4F203461-1372-49B7-A806-F130F168079E/Session-StreamusTests-2018-05-12_103414-MfIreE.log" UserInfo={NSLocalizedDescription=Test operation was canceled. If you believe this error represents a bug, please attach the log file at /var/folders/9v/vdbbf4j96hxgcxmtpntznytr0000gn/T/com.apple.dt.XCTest/IDETestRunSession-9A7EF764-6391-4C7D-9F34-066A9DFEC5E9/StreamusTests-4F203461-1372-49B7-A806-F130F168079E/Session-StreamusTests-2018-05-12_103414-MfIreE.log}
Testing failed:
Linker command failed with exit code 1 (use -v to see invocation)
** TEST FAILED **
The following build commands failed:
Ld /Users/oboujaouane/Library/Developer/Xcode/DerivedData/Streamus-gwtdwpbaxrfgafdtejzjtpxyhhhq/Build/Intermediates.noindex/Streamus.build/Alpha-iphonesimulator/StreamusTests.build/Objects-normal/x86_64/StreamusTests normal x86_64
Ld /Users/oboujaouane/Library/Developer/Xcode/DerivedData/Streamus-gwtdwpbaxrfgafdtejzjtpxyhhhq/Build/Intermediates.noindex/Streamus.build/Alpha-iphonesimulator/StreamusTests.build/Objects-normal/i386/StreamusTests normal i386
(2 failures)
returnValue=65
set +x
ERROR - Command 'xcodebuild clean build test -workspace Streamus.xcworkspace -scheme Streamus Alpha -configuration Debug -enableCodeCoverage YES -destination platform=iOS Simulator,name=iPhone 6,OS=11.3 -destination-timeout 60' failed with error code: 65
In advance thank you,
It seems that error was due to provisioning profile. When I added my Provisioning Profile and try it again the problem was resolved.
Then I had another problem with MessageKit:“Segmentation fault: 11”
It was a CocoaPods Podfile config issue.
So I had to switch compilation mode for Debug from "Single File" to "Whole Module” by click on Pods in Xcode project navigator then select MessageKit in targets of pods then Builds settings tab then in searcher tap ‘compilation mode’ and switch “Single File” to “Whole Module” and re-run script run-sonar-swift.sh

⚠️ each time you make a pod install / update or something that can change pods you have to switch compilation mode for Debug from "Single File" to "Whole Module” for the pod which give you an error when you launch run-sonar.swift.sh with -v for verbose.
After that it was not yet the end of my problems! In fact I had a last problem which was an error with SwipeCellKit pod:
“No such module SwipeCellKit”.
To resolve this problem follow instructions given here https://stackoverflow.com/a/37732248/6188918
Then I tried again and the rest of the script started (SwiftLint, Tailor & Lizard) and I thought this time it was finally good but an error occurred once again a new error message at the end of the script concerning Lizard which was:
ERROR: Error during SonarQube Scanner execution
ERROR: File
MyprojectName/Domains/Repositories/Local/cacheManager.swift can't be
indexed twice. Please check that inclusion/exclusion patterns produce
disjoint sets for main and test files
ERROR: Re-run SonarQube Scanner using the -X switch to enable full
debug logging.
To resolve this inclusion/exclusion I followed the answer given here:
https://stackoverflow.com/a/40150551/6188918
by adding these to line in sonar-project.properties file below sonar.swift.excludedPathsFromCoverage line:
sonar.test.inclusions=**/*Test*/**
sonar.exclusions=**/*Test*/**
I tried again but with parameter -notailor(run script and skip Tailor):
./run-sonar-swift.sh -notailor -v
just to save a little time because tailor take time
And after launch the script... Boom a new error... But it was a known issue:
Error: Caused by: org.sonar.api.measures.PersistenceMode
And the issue is explained here https://github.com/Backelite/sonar-swift/issues/118
So I downloaded this .jar file “backelite-sonar-swift-plugin-0.4-sonar-7-quick-fix.jar” found here https://github.com/Hugal31/sonar-swift/releases/tag/0.4-sonar-7-quick-fix and replace it in plugins of my local SonarQube and try again.
…and this time after an umpteenth launch I finally saw the light 🤪💡
Hope this answer will help and if you have a question don’t hesitate.


Good luck & have fun :)
PS: You’ll find here some options to run script with parameters:
./run-sonar-swift.sh -noswiftlint -v (run script with verbose option and skip SwiftLint)
./run-sonar-swift.sh -notailor -v (run script with verbose option and skip Tailor)
./run-sonar-swift.sh -nounittests -v (if your project does not have scheme configured to be tested launch with this parameter)
If you want more info check in run-sonar-swift.sh script and check around lines 125 ## COMMAND LINE OPTIONS
PS2: I have also opened an issue in sonar-swift GitHub if it can help: https://github.com/Backelite/sonar-swift/issues/138
I had an extra issue with oclint: oclint: Not enough positional command line arguments specified!. So I had to modify the run-sonar-swift.sh script a little bit in order to get it working: https://gist.github.com/Edudjr/79a2379842357c33709aecf040d9ae77#file-run-sonar-swift-sh
And this is a model of my sonar-project.properties: https://gist.github.com/Edudjr/db51907068ea76b116d11d9a9b13f05f#file-sonar-project-properties

Jenkins return "unknown error -1=ffffffffffffffff" when building Xcode Project with Cocoapods

I'm getting below error when trying to build Xcode workspace on Jenkins
usr/bin/codesign --force --sign B5E96BDFADAF51D771B158A29BF1D16565215A2D --preserve-metadata=identifier,entitlements '/Users/servicebuild/Desktop/Jenkins/workspace/Hello-Branch/build/Hello Test.app/Frameworks/Alamofire.framework'
16:06:07 /Users/servicebuild/Desktop/Jenkins/workspace/Hello-Branch/build/Hello Test.app/Frameworks/Alamofire.framework: unknown error -1=ffffffffffffffff
16:06:07 Command /bin/sh failed with exit code 1
16:06:07
16:06:07 ** BUILD FAILED **
16:06:07
16:06:07
16:06:07 The following build commands failed:
16:06:07 PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /Users/servicebuild/Library/Developer/Xcode/DerivedData/Hello-dcvxwbnovymfusbrvfyyekingznu/Build/Intermediates.noindex/Garanti\ Filo.build/Release-iphoneos/Hello\ Hello\ Test.build/Script-2617FEF7DE193736656550249B.sh
I have more than one targets and in workspace scheme targets that I created are ticked as shared (not the pod targets). In pod project every framework has "Don't Code Sign" (As Default). I can successfully get IPA export from Xcode. However, when I try to build in Jenkins I get this error.
I tried solution in below post but can't figure out. I think the problem is Jenkins is forcing to sign pods when It doesn't need to.
Codesign returned unknown error -1=ffffffffffffffff
I figured out how to run below code (posted in the post added in my question) and it worked. Important point is that giving right path for keychain and password. Otherwise, It doesn't work.
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k password ${KEYCHAIN}

Error no mobile provisioning profile found

While using the build system instruction from https://webrtc.org/native-code/ios/ all went fine except following error
Error: no mobile provisioning profile found for
When i do xcrun security find-identity -v -p codesigning i do see my certificates, Is there anyway to fix it?
$ gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
Done. Made 719 targets from 110 files in 2444ms
$ ninja -C out/ios_64 AppRTCMobile
ninja: Entering directory `out/ios_64'
[2086/2100] CODE SIGNING //webrtc/sdk:r...(//build/toolchain/mac:ios_clang_arm64)
FAILED: WebRTC.framework/WebRTC WebRTC.framework/_CodeSignature/CodeResources WebRTC.framework/embedded.mobileprovision
python ../../build/config/ios/codesign.py code-sign-bundle -t=iphoneos -i=3F06B010E7BE32A3D212219D02DF440B0F20D6A3 -e=../../build/config/ios/entitlements.plist -b=obj/webrtc/sdk/WebRTC WebRTC.framework
Error: no mobile provisioning profile found for "org.webrtc.WebRTC".
ninja: build stopped: subcommand failed.
Let me tell the steps that works for me
Edit the file src/examples/objc/AppRTCMobile/ios/Info.plist and change the value com.google.AppRTCMobile with your own bundle identifier.
Edit the file src/sdk/objc/Framework/Info.plist and change the value org.webrtc.WebRTC with your own bundle identifier
I have created bundle identifiers on Xcode and after that build is successful

Jenkins error: /usr/bin/codesign --force failed exit code 1

I am configuring CI for my IOS project on MAC yosemite-OS and got on problem:
error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,resource-rules --sign /Users/mitul/Desktop/jenkins_ios_profile/PCertificates.p12 --resource-rules=/var/folders/rj/cc6d38nn53v6tk8y4jn7ghkr0000gp/T/42RbMszHQX/Payload/XXX.app/ResourceRules.plist /var/folders/rj/cc6d38nn53v6tk8y4jn7ghkr0000gp/T/42RbMszHQX/Payload/XXX.app failed with error 1
even my build and archive are getting success but not able to make .ipa file
even tried all possibilities from this
/usr/bin/codesign failed with exit code 1 but no luck
Please help me what I am missing to do
My Xcode configuration is as follows:
Custom xcodebuild arguments:
CODE_SIGN_RESOURCE_RULES_PATH=/Users/mitul/Public/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ResourceRules.plist
rest are all with default setting
I unchecked the code signing checkbox in jenkins project configuration and it started building, hope it can help some else too!

Resources