我有一个问题,为什么要尝试使用 Jenkins 管道和 iOS 部分的 fastlane 构建 KMM 项目。
Kotlin 版本:1.5.31
XCode 版本:13.1
Fastlane 版本:2.198.1
Ruby 版本:2.6.3p62
在本地执行这些步骤时,它也会中断。fastlane 抛出的错误是import shared: no such module 'shared'
我发现如果你运行pod install && fastlane xcode_build
构建刹车,但如果你再次重复它,它会成功并在 XCode 的 DerivedData 文件夹中创建 project.app 文件。
Jenkinsfile 在另一个不是 KMM 的 iOS 项目上正常工作。
这是詹金斯文件
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
}
environment{
FIREBASE_APP = 'some-app'
FIREBASE_TOKEN = 'some-token'
YOUR_CRED = credentials('KeychainPassword')
PROJECT_NAME = 'project'
}
agent any
stages {
stage("Build and Deploy") {
parallel {
stage("iOS") {
agent { label 'ios' }
stages {
stage('Unlock Keychain') {
steps {
sh 'security unlock-keychain -p ${YOUR_CRED} /Users/chocho/Library/Keychains/login.keychain'
}
}
stage("Build") {
steps {
dir("${PROJECT_NAME}-ios"){
sh "pod install"
sh "fastlane xcode_build"
}
}
}
stage("Archive") {
steps {
sh "cp -r ~/Library/Developer/Xcode/DerivedData/${PROJECT_NAME}-ios*/Build/Products/Debug-iphonesimulator/${PROJECT_NAME}-ios.app ./"
sh "zip -r simulator.zip ./${PROJECT_NAME}-ios.app"
archiveArtifacts artifacts: 'simulator.zip', fingerprint: true
}
}
stage('Clean'){
steps{
sh "rm -rf ~/Library/Developer/Xcode/DerivedData/${PROJECT_NAME}*"
}
}
stage("Upload") {
// when { branch 'develop' }
steps {
dir("${PROJECT_NAME}-ios/fastlane"){
sh "fastlane test_flight_develop build_number:${BUILD_NUMBER}"
}
}
}
}
post {
always {
sh "rm -rf ~/Library/Developer/Xcode/DerivedData/${PROJECT_NAME}-ios*"
cleanWs()
}
}
}
stage("Android") {
agent { label 'ios' }
stages {
stage("Clean") {
when { branch 'develop' }
steps {
sh './gradlew clean'
}
}
stage("Build") {
when { branch 'develop' }
steps {
sh "./gradlew assembleRelease -Pandroid.injected.version.code=${BUILD_NUMBER}"
}
}
stage("Archive") {
when { branch 'develop' }
steps {
sh "cp ${PROJECT_NAME}-android/build/outputs/apk/release/${PROJECT_NAME}-android*.apk ./${PROJECT_NAME}-android.apk"
archiveArtifacts "${PROJECT_NAME}-android.apk"
}
}
stage("Upload") {
when { branch 'develop' }
steps {
sh "firebase appdistribution:distribute \
${PROJECT_NAME}-android.apk \
--token ${FIREBASE_TOKEN} \
--app ${FIREBASE_APP} \
--groups 'group'"
}
}
}
post {
always {
cleanWs()
}
}
}
}
}
}
}
这是我用于 fastlane 的 Fastfile
default_platform :ios
platform :ios do
lane :xcode_build do
xcodebuild(
scheme: schemeAndTarget,
workspace: schemeAndTarget + '.xcworkspace',
xcargs: "-configuration 'Debug' -sdk 'iphonesimulator15.0' -destination 'generic/platform=iOS Simulator'")
end
end
这是 Podfile
target 'project-ios' do
use_frameworks!
platform :ios, '14.5'
pod 'shared', :path => '../shared'
pod 'R.swift', '5.4.0'
pod 'SwiftLint', '0.45.0'
end
我的问题是,因为我对 KMM 的能力不够。为什么这样做?如果上述方法不可行,我打算如何为 CI/CD 构建项目。