Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import groovy.json.JsonSlurper
- import groovy.json.JsonBuilder
- node('master') {
- sendNotification("\uD83D\uDE80 Build started: ${env.JOB_NAME} <a href='${env.BUILD_URL}'>#${env.BUILD_ID}</a>")
- try {
- stage('checkout') {
- git credentialsId: '30e4e61b-f18e-4aec-92b1-da1cb44b72ea', branch: 'develop', url: 'https://stash.olegb.ru/scm/webimclntandr/webim-client-sdk-android.git'
- }
- stage('clean') {
- sh 'rm -rf sdk/build/libs/* && rm -rf sdk/build/outputs/aar/* && rm -rf demo/build/outputs/apk/*'
- }
- def version
- stage('read version') {
- if(!env.OVERRIDE_VERSION.isEmpty()) {
- version = ['version': env.OVERRIDE_VERSION]
- } else {
- def gitDesc = sh(script: 'git describe --tags --long', returnStdout: true).trim()
- def lastVTag = sh(script: "git log --decorate=full --simplify-by-decoration --pretty=oneline HEAD | " +
- "sed -r -e 's#^[^\\(]*\\(([^\\)]*)\\).*\$#\\1#' -e 's#,#\\n#g' | grep 'tag: v' | " +
- "sed -r -e 's#[[:space:]]*tag:[[:space:]]*##' | head -1", returnStdout: true).trim()
- if(lastVTag.isEmpty()) throw new RuntimeException('No tags prefixed with "v" found. Add version tag vefore build')
- version = getVersion(gitDesc, lastVTag);
- }
- echo 'Version: ' + version.version
- currentBuild.description = version.version
- }
- stage('build') {
- def tasks = ['build']
- if(env.BINTRAY_UPLOAD == 'true') tasks << 'bintrayUpload'
- if(env.CRASHLYTICS_UPLOAD == 'true') tasks << 'crashlyticsUploadDistributionRelease'
- withCredentials([[$class: 'StringBinding', credentialsId: 'bintray_api_key', variable: 'BINTRAY_API_KEY'],
- [$class: 'FileBinding', credentialsId: 'google_play_demo_app.jks', variable: 'KEYSTORE_FILE'],
- [$class: 'StringBinding', credentialsId: 'google_play_demo_app_jks_password', variable: 'KEYSTORE_PASSWORD'],
- [$class: 'StringBinding', credentialsId: 'google_play_demo_app_jks_alias', variable: 'KEYSTORE_ALIAS'],
- [$class: 'StringBinding', credentialsId: 'google_play_demo_app_jks_alias_password', variable: 'KEYSTORE_ALIAS_PASSWORD']]) {
- sh(
- './gradlew ' +
- tasks.join(' ') +
- ' --stacktrace' +
- ' -PversionName=' + version.version +
- ' -PversionCode=' + env.VERSION_CODE +
- ' -Pbintray.user=Webimdev' +
- ' -Pbintray.apikey=$BINTRAY_API_KEY' +
- ' -Pbintray.pkg.userOrg=webimdev' +
- ' -Pbintray.pkg.name=WebimSdkAndroid_dev' +
- ' -Pbintray.override=' + env.BINTRAY_OVERRIDE +
- ' -Pkeystore.path=$KEYSTORE_FILE' +
- ' -Pkeystore.password=$KEYSTORE_PASSWORD' +
- ' -Pkeystore.key.release.alias=$KEYSTORE_ALIAS' +
- ' -Pkeystore.key.release.password=$KEYSTORE_ALIAS_PASSWORD' +
- ' -PbetaDistributionEmails=\'' + env.CRASHLYTICS_DIST_EMAILS + '\''
- )
- }
- }
- def bintrayUrl = 'https://dl.bintray.com/webimdev/maven/com/webimapp/sdk/webimclientsdkandroid/' + version.version
- stage('archive') {
- // sh 'mkdir -p demo/build/outputs/lint && cp demo/build/outputs/lint-results-debug.html demo/build/outputs/lint/lint-results-debug.html'
- // sh 'mkdir -p sdk/build/outputs/lint && cp sdk/build/outputs/lint-results-debug.html sdk/build/outputs/lint/lint-results-debug.html'
- // publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'demo/build/outputs/lint/', reportFiles: 'lint-results-debug.html',
- // reportName: 'Demo android lint results'])
- // publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'sdk/build/outputs/lint/', reportFiles: 'lint-results-debug.html',
- // reportName: 'SDK android lint results'])
- archiveArtifacts allowEmptyArchive: true, artifacts: 'sdk/build/outputs/aar/webimclientsdkandroid-release.aar, demo/build/outputs/apk/demo-release.apk',
- onlyIfSuccessful: true
- if(env.BINTRAY_UPLOAD == 'true')
- manager.createSummary('document.png')
- .appendText("<a href='$bintrayUrl'>Bintray release</a>", false)
- }
- stage('write version') {
- if(env.OVERRIDE_VERSION.isEmpty())
- saveVersion(version)
- }
- def deployedList = []
- if(env.BINTRAY_UPLOAD == 'true') deployedList << "<a href='$bintrayUrl'>bintray</a> (dev)"
- if(env.CRASHLYTICS_UPLOAD == 'true') deployedList << 'Crashlytics Beta'
- sendNotification("\uD83D\uDE03 Build successful: ${env.JOB_NAME} <a href='${env.BUILD_URL}'>#${env.BUILD_ID}</a>\n" +
- "Version: ${version.version}" +
- (deployedList.isEmpty() ? '' : '\nPublished to: ' + deployedList.join(', ')))
- } catch(e) {
- try {
- sendNotification("\uD83D\uDE21 Build failed: ${env.JOB_NAME} <a href='${env.BUILD_URL}console'>#${env.BUILD_ID}</a>\n" + e.toString())
- } catch(ignored) {}
- throw e
- }
- }
- def sendNotification(def html) {
- //httpRequest 'https://api.telegram.org/bot274408872:AAHaYG_WTeaqnANal55uJHroiBmU74q4wek/sendMessage?' +
- // 'chat_id=-1001094070329&disable_web_page_preview=true&parse_mode=html&text=' + java.net.URLEncoder.encode(html)
- }
- @NonCPS
- def getVersion(def gitDesc, def lastVTag) {
- def (tag, commit) = getGitTagAndCommit(gitDesc)
- tag = lastVTag.substring(1) //removing 'v'
- def json = new JsonSlurper().parseText(env.VERSIONS_JSON)
- def revision = 0
- if(json.containsKey(tag)) {
- def part = json.get(tag)
- revision = part['revision'].toInteger()
- if(part['commit'] != commit || env.FORCE_INC_REV == 'true')
- revision++
- }
- def version;
- def suffix = env.PRE_RELEASE_SUFFIX
- if(suffix.isEmpty()) {
- version = tag+'.'+revision;
- } else {
- String[] parts = tag.split('\\.')
- String major = parts[0];
- int minor = parts[1].isEmpty() || parts[1] =='#' ? 0 : (parts[1].toInteger() + 1)
- version = major+'.'+minor+'.0-'+suffix+(revision == 0 ? '' : '.'+revision)
- }
- return ['version': version, 'tag': tag, 'revision': revision, 'commit': commit]
- }
- @NonCPS
- def saveVersion(def version) {
- def json = new JsonSlurper().parseText(env.VERSIONS_JSON)
- json[version.tag] = ['revision': version.revision, 'commit': version.commit]
- setPropertyDefaultValue('VERSIONS_JSON', new JsonBuilder(json).toPrettyString())
- }
- @NonCPS
- def setPropertyDefaultValue(def name, def newDefaultValue) {
- def paramsDef = manager.build.getParent().getProperty(ParametersDefinitionProperty.class)
- if (paramsDef) {
- paramsDef.parameterDefinitions.each{ param ->
- if (param.name == name) {
- if(param.defaultValue != newDefaultValue) {
- echo "Changing parameter ${param.name} default value was '${param.defaultValue}' to '${newDefaultValue}'"
- param.defaultValue = newDefaultValue
- manager.build.getParent().save()
- } else {
- echo "Parameter ${param.name} has not changed"
- }
- }
- }
- }
- }
- @NonCPS
- def getGitTagAndCommit(def gitDesc) {
- String[] parts = gitDesc.split('-')
- if(parts.length != 3) throw new RuntimeException('no git tags found')
- def tag = parts[0]
- def commit = parts[2].substring(1) //removing 'g'
- return [tag, commit]
- }
Add Comment
Please, Sign In to add comment