I have a Jenkins pipeline job that builds iOS code, creates .app file and runs tests against it. these jobs are triggered by PRs in the iOS repository. At a time there can be around 4-5 parallel builds running.
Configuration of build machine:
For example
jenkins-workspace-folder-on-mac-machine/
-> build/ (folder created by a job that builds .app file for a PR)
-> build@2/ (another folder created by a parallel job that builds .app for a PR)
-> build@3/ (another folder created by a parallel job that builds .app for a PR)
This is my Jenkinsfile script for reference:
stages {
stage('Clean Workspace') {
steps {
cleanWs deleteDirs: true, patterns: [[pattern: '**/Podfile.lock', type: 'EXCLUDE'], [pattern: '**/Pods/**', type: 'EXCLUDE'], [pattern: '**/Podfile', type: 'EXCLUDE'], [pattern: '**/Carthage/**', type: 'EXCLUDE'], [pattern: '**/Cartfile', type: 'EXCLUDE'], [pattern: '**/Cartfile.lock', type: 'EXCLUDE'], [pattern: '**/Cartfile.private', type: 'EXCLUDE'], [pattern: '**/Cartfile.resolved', type: 'EXCLUDE'], [pattern: '**/Gemfile', type: 'EXCLUDE'], [pattern: '**/Gemfile.lock', type: 'EXCLUDE']]
}
}
/* Download and checkout iOS repository in the workplace.
Also set all the keys for iOS into .env file */
stage('Checkout iOS Source repository') {
steps{
checkout([$class: 'GitSCM', branches: [[name: "${PR_BRANCH}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'abc', url: 'https://github.com/abc']]])
}
}
/* Install all dependencies. These will be skipped if repo folder is not cleaned in the beginning.
Full install will be done if an executor has to clone the repository from scratch*/
stage('Install dependencies') {
steps {
sh '''
bundle install
make install
'''
}
}
stage('Build .app file and trigger tests') {
steps {//This will perform xcode build and build .app file }
Issues I'm facing:
Podfile, Pod folder, podfile.lock, Carthage folder, Cartfile, Cartfile.private, Cartfile.resolved, Gemfile, Gemfile.lock
this would speed up the build. But that's not working.*** Checking out Nimble at "v8.0.4"
A shell task (/usr/bin/env git checkout --quiet --force v8.0.4 (launched in /Users/user/Library/Caches/org.carthage.CarthageKit/dependencies/Nimble)) failed with exit code 1:
error: pathspec 'v8.0.4' did not match any file(s) known to git
make: *** [carthage-install] Error 1
### Error
Errno::ENOENT - No such file or directory @ rb_file_s_stat - /Users/user/Library/Caches/CocoaPods/Pods/Release/Flurry-iOS-SDK/8.4.0-0c448
bundle exec pod install
Analyzing dependencies
Pre-downloading: `CLImageEditor` from `[email protected]/CLImageEditor.git`, commit `96e78cdf95761170d5bf11653a8257a3ccfeb19a`
[!] Failed to download 'CLImageEditor': Directory not empty @ dir_s_rmdir - /Users/user/Library/Caches/CocoaPods/Pods
make: *** [pod-install] Error 1
It would be great if someone could help understand what I'm doing wrong here.
I solved this problem by writing a script to manage cache of dependencies for cocoapods, gems and carthage based on different versions of Gemfile.lock, Podfile.lock & Cartfile.resolved.
Sample script in Jenkinsfile to manage cache
sh '''
set +x
mkdir -p ${HOME}/ioscache/pod
# CocoaPods
POD_SHASUM=$(shasum Podfile.lock | awk '{print $1}')
POD_KEY="pod-${POD_SHASUM}"
POD_CACHE_PATH="${HOME}/ioscache/pod/${POD_KEY}.tar.gz"
echo "Checking cache for CocoaPods with they key: $POD_KEY"
if [ ! -e "${POD_CACHE_PATH}" ]; then
echo "CocoaPods cache not found with the key: $POD_KEY"
POD_CACHE_FOUND=false
else
echo "CocoaPods cache found with the key: $POD_KEY"
echo "restoring cache.."
tar xf ${POD_CACHE_PATH}
POD_CACHE_FOUND=true
fi
make pod-install
if [ "$POD_CACHE_FOUND" = "false" ]; then
echo "Saving cache for CocoaPods with key: $POD_KEY"
tar cfz ${POD_CACHE_PATH} Pods/
echo "Saved."
fi
'''
Repeat the same for Gemfile.lock and Cartfile.resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With