Skip to content

Instantly share code, notes, and snippets.

@eriadam
Last active March 31, 2024 15:14
Show Gist options
  • Save eriadam/e20583d63e561587c727be629622acc1 to your computer and use it in GitHub Desktop.
Save eriadam/e20583d63e561587c727be629622acc1 to your computer and use it in GitHub Desktop.
example-jenkinsfile-pipeline.groovy
#!groovy
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Dependecies') {
steps {
sh '/usr/local/bin/pod install'
}
}
stage('Running Tests') {
steps {
parallel (
"Unit Tests": {
sh 'echo "Unit Tests"'
sh 'fastlane scan'
},
"UI Automation": {
sh 'echo "UI Automation"'
}
)
}
}
stage('Documentation') {
when {
expression {
env.BRANCH_NAME == 'develop'
}
}
steps {
// Generating docs
sh 'jazzy'
// Removing current version from web server
sh 'rm -rf /path/to/doc/ios'
// Copy new docs to web server
sh 'cp -a docs/source/. /path/to/doc/ios'
}
}
}
post {
always {
// Processing test results
junit 'fastlane/test_output/report.junit'
// Cleanup
sh 'rm -rf build'
}
success {
notifyBuild()
}
failure {
notifyBuild('ERROR')
}
}
}
// Slack notification with status and code changes from git
def notifyBuild(String buildStatus = 'SUCCESSFUL') {
buildStatus = buildStatus
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def changeSet = getChangeSet()
def message = "${subject} \n ${changeSet}"
if (buildStatus == 'SUCCESSFUL') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
slackSend (color: colorCode, message: message)
}
@NonCPS
// Fetching change set from Git
def getChangeSet() {
return currentBuild.changeSets.collect { cs ->
cs.collect { entry ->
"* ${entry.author.fullName}: ${entry.msg}"
}.join("\n")
}.join("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment