|
| 1 | +@Library('forge-shared-library')_ |
| 2 | + |
| 3 | +pipeline { |
| 4 | + agent { |
| 5 | + docker { |
| 6 | + image 'gradle:jdk8' |
| 7 | + args '-v gradlecache:/gradlecache' |
| 8 | + } |
| 9 | + } |
| 10 | + environment { |
| 11 | + GRADLE_ARGS = '-Dorg.gradle.daemon.idletimeout=5000' |
| 12 | + DISCORD_WEBHOOK = credentials('forge-discord-jenkins-webhook') |
| 13 | + DISCORD_PREFIX = "Job: ForgeGradle Branch: ${BRANCH_NAME} Build: #${BUILD_NUMBER}" |
| 14 | + JENKINS_HEAD = 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png' |
| 15 | + } |
| 16 | + |
| 17 | + stages { |
| 18 | + stage('fetch') { |
| 19 | + steps { |
| 20 | + checkout scm |
| 21 | + } |
| 22 | + } |
| 23 | + stage('notify_start') { |
| 24 | + when { |
| 25 | + not { |
| 26 | + changeRequest() |
| 27 | + } |
| 28 | + } |
| 29 | + steps { |
| 30 | + discordSend( |
| 31 | + title: "${DISCORD_PREFIX} Started", |
| 32 | + successful: true, |
| 33 | + result: 'ABORTED', //White border |
| 34 | + thumbnail: JENKINS_HEAD, |
| 35 | + webhookURL: DISCORD_WEBHOOK |
| 36 | + ) |
| 37 | + } |
| 38 | + } |
| 39 | + stage('buildandtest') { |
| 40 | + steps { |
| 41 | + withGradle { |
| 42 | + sh './gradlew ${GRADLE_ARGS} --refresh-dependencies --continue build test' |
| 43 | + } |
| 44 | + script { |
| 45 | + env.MYGROUP = sh(returnStdout: true, script: './gradlew properties -q | grep "group:" | awk \'{print $2}\'').trim() |
| 46 | + env.MYARTIFACT = sh(returnStdout: true, script: './gradlew properties -q | grep "name:" | awk \'{print $2}\'').trim() |
| 47 | + env.MYVERSION = sh(returnStdout: true, script: './gradlew properties -q | grep "version:" | awk \'{print $2}\'').trim() |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + stage('publish') { |
| 52 | + when { |
| 53 | + not { |
| 54 | + changeRequest() |
| 55 | + } |
| 56 | + } |
| 57 | + steps { |
| 58 | + withCredentials([usernamePassword(credentialsId: 'maven-forge-user', usernameVariable: 'MAVEN_USER', passwordVariable: 'MAVEN_PASSWORD')]) { |
| 59 | + withGradle { |
| 60 | + sh './gradlew ${GRADLE_ARGS} -PoldFormat=true uploadArchives' |
| 61 | + sh './gradlew ${GRADLE_ARGS} uploadArchives' |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + post { |
| 66 | + success { |
| 67 | + build job: 'filegenerator', parameters: [string(name: 'COMMAND', value: "promote ${env.MYGROUP}:${env.MYARTIFACT} ${env.MYVERSION} latest")], propagate: false, wait: false |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + post { |
| 73 | + always { |
| 74 | + script { |
| 75 | + if (env.CHANGE_ID == null) { // This is unset for non-PRs |
| 76 | + discordSend( |
| 77 | + title: "${DISCORD_PREFIX} Finished ${currentBuild.currentResult}", |
| 78 | + description: '```\n' + getChanges(currentBuild) + '\n```', |
| 79 | + successful: currentBuild.resultIsBetterOrEqualTo("SUCCESS"), |
| 80 | + result: currentBuild.currentResult, |
| 81 | + thumbnail: JENKINS_HEAD, |
| 82 | + webhookURL: DISCORD_WEBHOOK |
| 83 | + ) |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments