2019-02-16 04:16:49 +08:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
2019-03-13 23:54:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 - present Instructure, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of Canvas.
|
|
|
|
*
|
|
|
|
* Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
* Software Foundation, version 3 of the License.
|
|
|
|
*
|
|
|
|
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-12 09:55:34 +08:00
|
|
|
gems = [
|
2019-02-26 00:14:35 +08:00
|
|
|
'analytics',
|
|
|
|
'banner_grade_export_plugin',
|
|
|
|
'canvas_geoip',
|
|
|
|
'canvas_salesforce_plugin',
|
|
|
|
'canvas_webhooks',
|
|
|
|
'canvas_zendesk_plugin',
|
|
|
|
'canvasnet_registration',
|
|
|
|
'catalog_provisioner',
|
|
|
|
'custom_reports',
|
|
|
|
'demo_site',
|
|
|
|
'ims_es_importer_plugin',
|
|
|
|
'instructure_misc_plugin',
|
|
|
|
'migration_tool',
|
|
|
|
'multiple_root_accounts',
|
|
|
|
'phone_home_plugin',
|
|
|
|
'respondus_lockdown_browser',
|
|
|
|
'uuid_provisioner'
|
2019-02-21 01:22:05 +08:00
|
|
|
]
|
|
|
|
|
2019-02-26 00:14:35 +08:00
|
|
|
def withGerritCredentials = { Closure command ->
|
2019-02-28 23:53:11 +08:00
|
|
|
withCredentials([
|
|
|
|
sshUserPrivateKey(credentialsId: '44aa91d6-ab24-498a-b2b4-911bcb17cc35', keyFileVariable: 'SSH_KEY_PATH', usernameVariable: 'SSH_USERNAME')
|
|
|
|
]) { command() }
|
2019-02-21 01:22:05 +08:00
|
|
|
}
|
|
|
|
|
2019-03-05 05:09:25 +08:00
|
|
|
def fetchFromGerrit = { String repo, String path, String customRepoDestination = null, String sourcePath = null ->
|
2019-02-28 23:53:11 +08:00
|
|
|
withGerritCredentials({ ->
|
2019-02-26 00:14:35 +08:00
|
|
|
sh """
|
|
|
|
mkdir -p ${path}/${customRepoDestination ?: repo}
|
|
|
|
GIT_SSH_COMMAND='ssh -i \"$SSH_KEY_PATH\" -l \"$SSH_USERNAME\"' \
|
2019-03-14 05:29:43 +08:00
|
|
|
git archive --remote=ssh://$GERRIT_URL/${repo} master ${sourcePath == null ? '' : sourcePath} | tar -x -v -C ${path}/${customRepoDestination ?: repo}
|
2019-02-26 00:14:35 +08:00
|
|
|
"""
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:23:12 +08:00
|
|
|
def getImageTag() {
|
2019-03-12 09:55:34 +08:00
|
|
|
// if (env.GERRIT_EVENT_TYPE == 'patchset-created') {
|
|
|
|
// GERRIT__REFSPEC will be in the form 'refs/changes/63/181863/8'
|
|
|
|
// we want a name in the form '63.181863.8'
|
|
|
|
NAME = "${env.GERRIT_REFSPEC}".minus('refs/changes/').replaceAll('/','.')
|
|
|
|
return "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$NAME"
|
|
|
|
// } else {
|
|
|
|
// return "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$GERRIT_BRANCH"
|
|
|
|
// }
|
2019-02-22 10:23:12 +08:00
|
|
|
}
|
|
|
|
|
2019-02-16 04:16:49 +08:00
|
|
|
pipeline {
|
2019-02-21 01:06:06 +08:00
|
|
|
agent { label 'docker' }
|
2019-02-16 04:16:49 +08:00
|
|
|
|
2019-02-21 01:06:06 +08:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
2019-02-21 01:22:05 +08:00
|
|
|
parallelsAlwaysFailFast()
|
2019-02-21 01:06:06 +08:00
|
|
|
}
|
2019-02-20 23:41:00 +08:00
|
|
|
|
2019-02-21 01:06:06 +08:00
|
|
|
environment {
|
2019-03-12 09:55:34 +08:00
|
|
|
GERRIT_PORT = '29418'
|
2019-02-21 01:22:05 +08:00
|
|
|
GERRIT_URL = "$GERRIT_HOST:$GERRIT_PORT"
|
2019-02-22 10:23:12 +08:00
|
|
|
IMAGE_TAG = getImageTag()
|
2019-02-21 01:06:06 +08:00
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
|
2019-02-21 01:06:06 +08:00
|
|
|
stages {
|
2019-02-26 00:14:35 +08:00
|
|
|
stage('Debug') {
|
|
|
|
steps {
|
2019-03-12 09:55:34 +08:00
|
|
|
timeout(time: 20, unit: 'SECONDS') {
|
|
|
|
sh 'printenv | sort'
|
|
|
|
}
|
2019-02-26 00:14:35 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-21 01:22:05 +08:00
|
|
|
|
2019-03-12 09:55:34 +08:00
|
|
|
stage('Plugins and Config Files') {
|
|
|
|
steps {
|
|
|
|
timeout(time: 3) {
|
|
|
|
script {
|
|
|
|
withGerritCredentials({ ->
|
|
|
|
sh '''
|
|
|
|
gerrit_message="Gerrit Builder Started $JOB_BASE_NAME\nTag: $IMAGE_TAG\nBuild: $BUILD_URL"
|
|
|
|
ssh -i "$SSH_KEY_PATH" -l "$SSH_USERNAME" -p $GERRIT_PORT \
|
|
|
|
hudson@$GERRIT_HOST gerrit review -m "'$gerrit_message'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER
|
|
|
|
'''
|
|
|
|
})
|
2019-03-13 04:14:09 +08:00
|
|
|
gems.each { gem -> fetchFromGerrit(gem, 'gems/plugins') }
|
2019-03-12 09:55:34 +08:00
|
|
|
fetchFromGerrit('qti_migration_tool', 'vendor', 'QTIMigrationTool')
|
2019-03-14 05:29:43 +08:00
|
|
|
fetchFromGerrit('gerrit_builder', '.', '', 'canvas-lms/config')
|
|
|
|
sh 'mv gerrit_builder/canvas-lms/config/* config/'
|
|
|
|
sh 'rmdir -p gerrit_builder/canvas-lms/config'
|
2019-02-21 01:22:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:09:25 +08:00
|
|
|
stage('Rebase') {
|
|
|
|
when { expression { env.GERRIT_EVENT_TYPE == 'patchset-created' } }
|
|
|
|
steps {
|
|
|
|
sh '''
|
|
|
|
git config user.name $GERRIT_EVENT_ACCOUNT_NAME
|
|
|
|
git config user.email $GERRIT_EVENT_ACCOUNT_EMAIL
|
|
|
|
git rebase --preserve-merges origin/$GERRIT_BRANCH
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:22:05 +08:00
|
|
|
stage('Build Image') {
|
2019-02-21 01:06:06 +08:00
|
|
|
steps {
|
2019-03-14 00:33:24 +08:00
|
|
|
timeout(time: 36) { /* this timeout is `2 * average build time` which currently: 18m * 2 = 36m */
|
2019-02-21 01:22:05 +08:00
|
|
|
sh 'docker build -t $IMAGE_TAG .'
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|
2019-02-21 01:06:06 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
|
2019-03-12 09:55:34 +08:00
|
|
|
stage('Publish Image') {
|
2019-02-21 01:06:06 +08:00
|
|
|
steps {
|
2019-03-12 09:55:34 +08:00
|
|
|
timeout(time: 5) {
|
2019-02-21 01:22:05 +08:00
|
|
|
sh 'docker push $IMAGE_TAG'
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|
2019-02-21 01:06:06 +08:00
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|
2019-02-21 01:06:06 +08:00
|
|
|
}
|
2019-03-12 09:55:34 +08:00
|
|
|
|
|
|
|
post {
|
|
|
|
success {
|
|
|
|
script {
|
|
|
|
withGerritCredentials({ ->
|
|
|
|
sh '''
|
|
|
|
gerrit_message="Gerrit Builder $JOB_BASE_NAME Successful.\nTag: $IMAGE_TAG\nBuild: $BUILD_URL"
|
|
|
|
ssh -i "$SSH_KEY_PATH" -l "$SSH_USERNAME" -p $GERRIT_PORT \
|
|
|
|
hudson@$GERRIT_HOST gerrit review -m "'$gerrit_message'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER
|
|
|
|
'''
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsuccessful {
|
|
|
|
script {
|
|
|
|
withGerritCredentials({ ->
|
|
|
|
sh '''
|
|
|
|
gerrit_message="Gerrit Builder $JOB_BASE_NAME Failed.\nTag: $IMAGE_TAG\nBuild: $BUILD_URL"
|
|
|
|
ssh -i "$SSH_KEY_PATH" -l "$SSH_USERNAME" -p $GERRIT_PORT \
|
|
|
|
hudson@$GERRIT_HOST gerrit review -m "'$gerrit_message'" $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER
|
|
|
|
'''
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|