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-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-20 23:16:16 +08:00
|
|
|
COMPOSE_FILE = 'docker-compose.new-jenkins.yml'
|
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-03-20 23:16:16 +08:00
|
|
|
// 'refs/changes/63/181863/8' -> '63.181863.8'
|
2019-03-15 01:44:25 +08:00
|
|
|
NAME = "${env.GERRIT_REFSPEC}".minus('refs/changes/').replaceAll('/','.')
|
|
|
|
PATCHSET_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$NAME"
|
|
|
|
MERGE_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$GERRIT_BRANCH"
|
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 {
|
2019-03-20 23:16:16 +08:00
|
|
|
/* send message to gerrit */
|
2019-03-12 09:55:34 +08:00
|
|
|
withGerritCredentials({ ->
|
|
|
|
sh '''
|
2019-04-11 06:18:18 +08:00
|
|
|
gerrit_message="\u2615 $JOB_BASE_NAME build started.\nTag: canvas-lms:$NAME\n$BUILD_URL"
|
2019-03-12 09:55:34 +08:00
|
|
|
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-20 23:16:16 +08:00
|
|
|
|
|
|
|
/* fetch plugins */
|
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')
|
2019-03-20 23:16:16 +08:00
|
|
|
sh '''
|
|
|
|
mv gerrit_builder/canvas-lms/config/* config/
|
|
|
|
rmdir -p gerrit_builder/canvas-lms/config
|
|
|
|
cp docker-compose/config/selenium.yml 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 {
|
2019-03-20 23:16:16 +08:00
|
|
|
timeout(time: 2) {
|
|
|
|
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-04-11 03:19:55 +08:00
|
|
|
rebase_exit_code="$?"
|
|
|
|
if [ $rebase_exit_code != 0 ]; then
|
|
|
|
echo "Warning: Rebase couldn't resolve changes automatically, please resolve these conflicts locally."
|
|
|
|
git rebase --abort
|
|
|
|
fi
|
2019-03-20 23:16:16 +08:00
|
|
|
'''
|
|
|
|
}
|
2019-03-05 05:09:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-03-15 01:44:25 +08:00
|
|
|
sh 'docker build -t $PATCHSET_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-20 23:16:16 +08:00
|
|
|
stage('Smoke Test') {
|
|
|
|
steps {
|
|
|
|
timeout(time: 10) {
|
|
|
|
sh 'build/new-jenkins/smoke-test.sh'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-03-15 01:44:25 +08:00
|
|
|
script {
|
2019-03-20 23:16:16 +08:00
|
|
|
// always push the patchset tag otherwise when a later
|
|
|
|
// patchset is merged this patchset tag is overwritten
|
|
|
|
sh 'docker push $PATCHSET_TAG'
|
|
|
|
|
|
|
|
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
|
2019-03-15 01:44:25 +08:00
|
|
|
sh '''
|
|
|
|
docker tag $PATCHSET_TAG $MERGE_TAG
|
|
|
|
docker push $MERGE_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 '''
|
2019-04-11 06:18:18 +08:00
|
|
|
gerrit_message="\u2713 $JOB_BASE_NAME build successful.\nTag: canvas-lms:$NAME\n$BUILD_URL"
|
2019-03-12 09:55:34 +08:00
|
|
|
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 '''
|
2019-04-11 06:18:18 +08:00
|
|
|
gerrit_message="\u274C $JOB_BASE_NAME build failed.\nTag: canvas-lms:$NAME\n$BUILD_URL"
|
2019-03-12 09:55:34 +08:00
|
|
|
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-20 23:16:16 +08:00
|
|
|
|
|
|
|
cleanup {
|
|
|
|
script {
|
|
|
|
sh 'docker-compose down --volumes --rmi local'
|
|
|
|
}
|
|
|
|
}
|
2019-03-12 09:55:34 +08:00
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|