|
| 1 | +@Library('jenkins-shared-libraries') _ |
| 2 | + |
| 3 | +def ARTIFACT_ID = 'strongbox-database-ui' |
| 4 | +def SERVER_ID = 'carlspring-oss-snapshots' |
| 5 | +def DEPLOY_SERVER_URL = 'https://repo.carlspring.org/content/repositories/carlspring-oss-snapshots/' |
| 6 | +def PR_SERVER_URL = 'https://repo.carlspring.org/content/repositories/carlspring-oss-pull-requests/' |
| 7 | + |
| 8 | +// Notification settings for "master" and "branch/pr" |
| 9 | +def notifyMaster = [notifyAdmins: true, recipients: [culprits(), requestor()]] |
| 10 | +def notifyBranch = [recipients: [brokenTestsSuspects(), requestor()], notifyByChat: false] |
| 11 | + |
| 12 | +pipeline { |
| 13 | + agent { |
| 14 | + label 'ubuntu-jdk8-mvn3.6-node12-browsers' |
| 15 | + } |
| 16 | + parameters { |
| 17 | + booleanParam(defaultValue: false, description: 'Force deploy?', name: 'FORCE_DEPLOY') |
| 18 | + booleanParam(defaultValue: false, description: 'Clear .npm cache on node?', name: 'CLEAR_CACHE') |
| 19 | + booleanParam(defaultValue: true, description: 'Send email notification?', name: 'NOTIFY_EMAIL') |
| 20 | + } |
| 21 | + options { |
| 22 | + timeout(time: 2, unit: 'HOURS') |
| 23 | + disableConcurrentBuilds() |
| 24 | + } |
| 25 | + environment { |
| 26 | + // Necessary for NPM to avoid being asked questions. |
| 27 | + CI="true" |
| 28 | + } |
| 29 | + stages { |
| 30 | + stage('Node') { |
| 31 | + steps { |
| 32 | + container("node") { |
| 33 | + nodeInfo("npm yarn node mvn") |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + stage('Install dependencies') { |
| 38 | + steps { |
| 39 | + script { |
| 40 | + container("node") { |
| 41 | + def npmCachePath = workspace().getNPMCachePath() |
| 42 | + |
| 43 | + if(params.CLEAR_CACHE) { |
| 44 | + sh label: "Clearing ${npmCachePath}", script: "rm -rf ${npmCachePath}/*" |
| 45 | + } |
| 46 | + |
| 47 | + sh label: "Set NPM cache directory", script: "npm config set cache ${npmCachePath}" |
| 48 | + sh label: "Install dependencies", script: "npm install" |
| 49 | + sh label: "List installed packages", script: "npm ls --depth=0 || echo ''" |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + stage('Build') { |
| 55 | + steps { |
| 56 | + container("node") { |
| 57 | + sh "npm run ci-build" |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + stage('Tests') { |
| 62 | + parallel { |
| 63 | + stage('ci-test') { |
| 64 | + steps { |
| 65 | + script { |
| 66 | + container("node") { |
| 67 | + try { |
| 68 | + sh "npm run ci-test" |
| 69 | + } catch (e) { |
| 70 | + if(!params.FORCE_DEPLOY) { |
| 71 | + currentBuild.result = 'FAILURE' |
| 72 | + throw e |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + stage('Deploy') { |
| 82 | + when { |
| 83 | + expression { (params.FORCE_DEPLOY || currentBuild.result == null || currentBuild.result == 'SUCCESS') } |
| 84 | + } |
| 85 | + steps { |
| 86 | + script { |
| 87 | + container("node") { |
| 88 | + withMavenPlus(mavenLocalRepo: workspace().getM2LocalRepoPath(), mavenSettingsConfig: 'a5452263-40e5-4d71-a5aa-4fc94a0e6833', publisherStrategy: 'EXPLICIT', options: [artifactsPublisher(), mavenLinkerPublisher()]) |
| 89 | + { |
| 90 | + def SERVER_URL; |
| 91 | + def VERSION_ID; |
| 92 | + |
| 93 | + if (BRANCH_NAME == 'master') { |
| 94 | + echo "Deploying master..." |
| 95 | + SERVER_URL = DEPLOY_SERVER_URL; |
| 96 | + VERSION_ID = "1.0-SNAPSHOT" |
| 97 | + } else { |
| 98 | + echo "Deploying branch/PR" |
| 99 | + SERVER_URL = PR_SERVER_URL; |
| 100 | + if(env.CHANGE_ID) { |
| 101 | + VERSION_ID = "1.0-PR-${env.CHANGE_ID}-SNAPSHOT" |
| 102 | + } else { |
| 103 | + VERSION_ID = "1.0-${BRANCH_NAME}-SNAPSHOT" |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + sh "mvn deploy:deploy-file " + |
| 108 | + " -Dfile=./dist/packaging/"+ ARTIFACT_ID +".zip " + |
| 109 | + " -DrepositoryId=" + SERVER_ID + |
| 110 | + " -Durl=" + SERVER_URL + |
| 111 | + " -DartifactId=" + ARTIFACT_ID + |
| 112 | + " -DgroupId=org.carlspring.strongbox" + |
| 113 | + " -Dpackaging=zip" + |
| 114 | + " -Dversion=" + VERSION_ID |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + post { |
| 122 | + failure { |
| 123 | + script { |
| 124 | + if(params.NOTIFY_EMAIL) { |
| 125 | + notifyFailed((BRANCH_NAME == "master") ? notifyMaster : notifyBranch) |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + unstable { |
| 130 | + script { |
| 131 | + if(params.NOTIFY_EMAIL) { |
| 132 | + notifyUnstable((BRANCH_NAME == "master") ? notifyMaster : notifyBranch) |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + fixed { |
| 137 | + script { |
| 138 | + if(params.NOTIFY_EMAIL) { |
| 139 | + notifyFixed((BRANCH_NAME == "master") ? notifyMaster : notifyBranch) |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + always { |
| 144 | + container("node") { |
| 145 | + junit 'dist/TESTS-*.xml' |
| 146 | + } |
| 147 | + |
| 148 | + script { |
| 149 | + |
| 150 | + def isSuccessful = currentBuild.result == 'SUCCESS'; |
| 151 | + |
| 152 | + if((params.TRIGGER_STRONGBOX && isSuccessful) || params.FORCE_DEPLOY) { |
| 153 | + if(BRANCH_NAME == "master") { |
| 154 | + build job: '/strongbox/builds/strongbox/master', |
| 155 | + wait: false, |
| 156 | + parameters: [ |
| 157 | + string(name: 'INTEGRATION_TESTS_BRANCH', value: 'master'), |
| 158 | + booleanParam(name: 'RUN_ONLY_SMOKE', value: false), |
| 159 | + booleanParam(name: 'SKIP_TESTS', value: false), |
| 160 | + booleanParam(name: 'DEPLOY', value: true), |
| 161 | + booleanParam(name: 'NOTIFY_EMAIL', value: true) |
| 162 | + ] |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | +} |
0 commit comments