2016-12-06 60 views

回答

5

是的,這是完全可能的。您只需從命令行執行所有操作,而不是XCode或您選擇的IDE。在iOS的情況下,請查看react-native bundle命令以創建JS軟件包,並編譯xcodebuildxcrun以編譯本機代碼。在Android中,它更容易一些,因爲您擁有gradle assembleRelease任務。在此之前,您必須運行npm install以獲取所有依賴關係,但這應該大致如此。

至於iOS開發,不幸的是沒有辦法繞過它,你確實需要一臺OS X機器。

+0

能否請您提供鏈接 –

+0

不幸的是,在React Native網頁上沒有關於該主題的文檔,所以很難指出您到某個特定的地方。我個人使用[fastlane](https://fastlane.tools/),並遵循非常標準的配置。 – martinarroyo

+0

martinarroyo是否還有其他我可以遵循的文檔或腳本示例? – Jan

2

第一件事就是讓命令行構建適用於Android和iOS。您可以在Xcode或Android Studio日誌中達到最高點並複製一些命令。

我在ios和android文件夾中放置了一個build.sh腳本,我可以從Jenkins作業調用它來構建相應的目標。您可以在調用兩者的項目根目錄中擁有build.sh。

TODO:我想弄清楚如何在詹金斯的工作運行eslint的Airbnb和生成報告?

這裏是我的iOS BUILD.sh中,與Xcode的9作品:

#!/bin/sh 
############################################ 
# File: build.sh 
# ----------------------- 
# Author: [email protected] 
# 
# Command line build: 
# 1) clean 
# 2) build 
# 3) archive 
# 4) export IPA 
# 
# http://shashikantjagtap.net/xcodebuild-deploy-ios-app-command-line/ 
# https://help.apple.com/itc/apploader/e3#/apdATD1E53-D1E1A1303-D1E53A1126 
# 

isInPath=$(which xcodebuild) 
if [ ! -x "${isInPath}" ] ; then 
    echo "*** Error xcodebuild not found in path" 
    exit 1 
fi 

isInPath=$(which xcrun) 
if [ ! -x "${isInPath}" ] ; then 
    echo "*** Error xcrun not found in path" 
    exit 1 
fi 


echo "### Start: Cleaning ###############################################################" 
rm -rf build 
xcodebuild -project MyApp.xcodeproj -scheme MyApp -destination generic/platform=iOS clean  
echo "### Done: Cleaning ###############################################################" 

# Analyze 
# xcodebuild -project MyApp.xcodeproj -scheme MyApp -sdk iphoneos clean analyze 

echo "### Start: Building ###############################################################" 
# xcodebuild -project MyApp.xcodeproj -target MyApp -showBuildSettings 
# xcodebuild -project MyApp.xcodeproj -scheme MyApp -destination generic/platform=iOS build  

# Run pod install once before building workspace 
pod install 

# Now using a Podfile so have to build workspace not build project 
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -destination generic/platform=iOS build  
echo "### Done: Building ###############################################################" 


CFBundleShortVersionString=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" ./MyApp/Info.plist` 
CFBundleVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" ./MyApp/Info.plist` 
echo "CFBundleShortVersionString: ${CFBundleShortVersionString}" 
echo "CFBundleVersion: ${CFBundleVersion}" 

ipaFileName=MyApp.ipa 
renameIpaFileName="field-scout-${CFBundleShortVersionString}.${CFBundleVersion}.ipa" 

echo "### Start: Archiving ###############################################################" 
# xcodebuild -project MyApp.xcodeproj -scheme MyApp -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/MyApp.xcarchive 

# Now using a Podfile so have to build workspace not build project 
xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -sdk iphoneos -configuration AppStoreDistribution archive -archivePath $PWD/build/MyApp.xcarchive 
echo "### Done: Archiving ###############################################################" 

echo "### Start: Exporting ###############################################################" 
xcodebuild -exportArchive -archivePath $PWD/build/MyApp.xcarchive -exportOptionsPlist MyApp/ExportOptions.plist -exportPath $PWD/build 
ls -al build 
echo "### Done: Exporting ###############################################################" 

appArchiveFile=build/${ipaFileName} 
if [ ! -f "${appArchiveFile}" ]; then 
    echo "*** Error file not found: ${appArchiveFile}" 
    exit 1  
fi 

# Extract and verify archive contents 
echo "### Unzip: ${ipaFileName} ###############################################################" 
(cd build; unzip -q ${ipaFileName}) 
(cd build/Payload; xcrun codesign -dv MyApp.app/) 

outputFile=build/Payload/MyApp.app 
if [ ! -d "${outputFile}" ]; then 
    echo "*** Error file not found: ${outputFile}" 
    exit 1  
fi 
rm -rf ./build/Payload 
rm -rf ./build/Symbols 


# altool is used to verify iOS IPA files 
altool_path=/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/Current/Support 

isInPath=$(which altool) 
if [ ! -x "${isInPath}" ] ; then 
    echo "*** Error altool not found in path" 
    echo "Expected altool path:\n ${altool_path}" 
    exit 1 
fi 

# altool validate will trigger a user dialog first time it is run. 
# On a jenkins slave you will need to execute manually in a console once, to allow keychain access. 
# $ altool --validate-app -f file -u username [-p password] [--output-format xml] 
# $ altool --upload-app -f file -u username [-p password] [--output-format xml] 
altool --validate-app -f build/${ipaFileName} -u [email protected] -p @keychain:"Application Loader: [email protected]" 
altool --validate-app -f build/${ipaFileName} -u [email protected] -p @keychain:"Application Loader: [email protected]" --output-format xml > build/validate.xml 
altoolValidate=$? 
if [ ${altoolValidate} -ne 0 ]; then 
    echo "*** Error IPA failed to validate: build/${ipaFileName}" 
    echo "See: build/validate.xml" 
    exit 1  
fi 

echo "Rename build/${ipaFileName} to build/${renameIpaFileName}" 
mv ./build/${ipaFileName} ./build/${renameIpaFileName} 

echo ############################## 
echo  Done 
echo ############################## 
echo Ready to upload archive to iTunes: 
echo " ${appArchiveFile}" 
echo 
uploadExample="$(echo altool --upload-app -f build/${renameIpaFileName} -u [email protected] -p @keychain:"Application Loader: [email protected]")" 
echo "Upload Example:\n ${uploadExample}" 
echo 
+0

測試我們在Jenkinsfile有這樣的: 'builderNode {// TODO:創紀錄的業績 階段( 「測試」){ SH「泊塢窗運行--rm -i '$ {imageName}'紗線測試「 } }' – Cole