Last active
April 15, 2019 19:09
-
-
Save mlabouardy/f79a04731f12b7527cbfc189fa44a49c to your computer and use it in GitHub Desktop.
CI/CD for iOS apps on Jenkins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bucket = 'mobile-artifacts-foxintelligence' | |
node('mac') { | |
try { | |
stage('Checkout') { | |
checkout scm | |
notifySlack('STARTED') | |
} | |
stage('Install Dependencies') { | |
sh "pod install" | |
} | |
stage('Build') { | |
if (env.BRANCH_NAME == 'master'){ | |
sh "bundle exec fastlane prod_testflight" | |
} | |
if (env.BRANCH_NAME == 'preprod'){ | |
sh "bundle exec fastlane staging" | |
} | |
if (env.BRANCH_NAME == 'develop'){ | |
sh "bundle exec fastlane develop" | |
} | |
} | |
stage('Push') { | |
sh "aws s3 cp Cleanfox.ipa s3://${bucket}/ios/cleanfox-${commitID()}.ipa" | |
if (env.BRANCH_NAME == 'master'){ | |
sh "aws s3 cp Cleanfox.ipa s3://${bucket}/ios/cleanfox-latest.ipa" | |
} | |
if (env.BRANCH_NAME == 'preprod'){ | |
sh "aws s3 cp Cleanfox.ipa s3://${bucket}/ios/cleanfox-preprod.ipa" | |
} | |
if (env.BRANCH_NAME == 'develop'){ | |
sh "aws s3 cp Cleanfox.ipa s3://${bucket}/ios/cleanfox-develop.ipa" | |
} | |
} | |
stage('Test') { | |
if (env.BRANCH_NAME == 'master'){ | |
sh 'bundle fastlane tests --scheme "Production"' | |
} | |
if (env.BRANCH_NAME == 'preprod'){ | |
sh 'bundle fastlane tests --scheme "Staging"' | |
} | |
if (env.BRANCH_NAME == 'develop'){ | |
sh 'bundle fastlane tests --scheme "Sandbox"' | |
} | |
} | |
}catch(e){ | |
currentBuild.result = 'FAILED' | |
throw e | |
}finally{ | |
notifySlack(currentBuild.result) | |
} | |
} | |
def notifySlack(String buildStatus){ | |
buildStatus = buildStatus ?: 'SUCCESSFUL' | |
def colorCode = '#FF0000' | |
def subject = "Name: '${env.JOB_NAME}'\nStatus: ${buildStatus}\nBuild ID: ${env.BUILD_NUMBER}" | |
def summary = "${subject}\nMessage: ${commitMessage()}\nAuthor: ${commitAuthor()}\nURL: ${env.BUILD_URL}" | |
if (buildStatus == 'STARTED') { | |
colorCode = '#546e7a' | |
} else if (buildStatus == 'SUCCESSFUL') { | |
colorCode = '#2e7d32' | |
} else { | |
colorCode = '#c62828c' | |
} | |
slackSend (color: colorCode, message: summary) | |
} | |
def commitAuthor(){ | |
sh 'git show -s --pretty=%an > .git/commitAuthor' | |
def commitAuthor = readFile('.git/commitAuthor').trim() | |
sh 'rm .git/commitAuthor' | |
commitAuthor | |
} | |
def commitID() { | |
sh 'git rev-parse HEAD > .git/commitID' | |
def commitID = readFile('.git/commitID').trim() | |
sh 'rm .git/commitID' | |
commitID | |
} | |
def commitMessage() { | |
sh 'git log --format=%B -n 1 HEAD > .git/commitMessage' | |
def commitMessage = readFile('.git/commitMessage').trim() | |
sh 'rm .git/commitMessage' | |
commitMessage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment