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-10-31 23:22:09 +08:00
|
|
|
def fullSuccessName(name) {
|
|
|
|
return "_successes/${env.GERRIT_CHANGE_NUMBER}-${env.GERRIT_PATCHSET_NUMBER}-${name}-success"
|
|
|
|
}
|
|
|
|
|
|
|
|
def hasSuccess(name) {
|
|
|
|
copyArtifacts(filter: "_successes/*",
|
|
|
|
optional: true,
|
|
|
|
projectName: '/${JOB_NAME}',
|
|
|
|
parameters: "GERRIT_CHANGE_NUMBER=${env.GERRIT_CHANGE_NUMBER},GERRIT_PATCHSET_NUMBER=${GERRIT_PATCHSET_NUMBER}",
|
|
|
|
selector: lastCompleted())
|
|
|
|
if (fileExists("_successes")) {
|
|
|
|
archiveArtifacts(artifacts: "_successes/*",
|
|
|
|
projectName: '/${JOB_NAME}')
|
|
|
|
}
|
|
|
|
return fileExists(fullSuccessName(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
def saveSuccess(name) {
|
|
|
|
def success_name = fullSuccessName(name)
|
|
|
|
sh "mkdir -p _successes"
|
|
|
|
sh "echo 'success' >> ${success_name}"
|
|
|
|
archiveArtifacts(artifacts: "_successes/*",
|
|
|
|
projectName: '/${JOB_NAME}')
|
|
|
|
echo "===> success saved /${env.JOB_NAME}: ${success_name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
// runs the body if it has not previously succeeded.
|
|
|
|
// if you don't want the success of the body to mark the
|
|
|
|
// given name as successful, pass in save = false.
|
|
|
|
def skipIfPreviouslySuccessful(name, save = true, body) {
|
|
|
|
if (hasSuccess(name)) {
|
|
|
|
echo "===> block already successful, skipping: ${fullSuccessName(name)}"
|
|
|
|
} else {
|
|
|
|
echo "===> running block: ${fullSuccessName(name)}"
|
|
|
|
body.call()
|
|
|
|
if (save) saveSuccess(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 02:43:09 +08:00
|
|
|
def build_parameters = [
|
|
|
|
string(name: 'GERRIT_REFSPEC', value: "${env.GERRIT_REFSPEC}"),
|
|
|
|
string(name: 'GERRIT_EVENT_TYPE', value: "${env.GERRIT_EVENT_TYPE}"),
|
|
|
|
string(name: 'GERRIT_BRANCH', value: "${env.GERRIT_BRANCH}"),
|
|
|
|
string(name: 'GERRIT_CHANGE_NUMBER', value: "${env.GERRIT_CHANGE_NUMBER}"),
|
|
|
|
string(name: 'GERRIT_PATCHSET_NUMBER', value: "${env.GERRIT_PATCHSET_NUMBER}"),
|
|
|
|
string(name: 'GERRIT_EVENT_ACCOUNT_NAME', value: "${env.GERRIT_EVENT_ACCOUNT_NAME}"),
|
2019-11-16 02:12:18 +08:00
|
|
|
string(name: 'GERRIT_EVENT_ACCOUNT_EMAIL', value: "${env.GERRIT_EVENT_ACCOUNT_EMAIL}"),
|
|
|
|
string(name: 'GERRIT_CHANGE_COMMIT_MESSAGE', value: "${env.GERRIT_CHANGE_COMMIT_MESSAGE}"),
|
|
|
|
string(name: 'GERRIT_HOST', value: "${env.GERRIT_HOST}"),
|
|
|
|
string(name: 'GERGICH_PUBLISH', value: "0")
|
2019-08-15 02:43:09 +08:00
|
|
|
]
|
|
|
|
|
2019-11-16 02:12:18 +08:00
|
|
|
def getImageTagVersion() {
|
|
|
|
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
|
|
|
|
return flags.getImageTagVersion()
|
|
|
|
}
|
|
|
|
|
|
|
|
def runBuildImageMaybe(save_success, block) {
|
|
|
|
def flags = load 'build/new-jenkins/groovy/commit-flags.groovy'
|
|
|
|
if (flags.hasFlag('skip-docker-build')) {
|
|
|
|
echo "skip building image requested"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
skipIfPreviouslySuccessful("build-and-push-image", save_success, block)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 04:16:49 +08:00
|
|
|
pipeline {
|
2019-09-07 02:03:00 +08:00
|
|
|
agent { label 'canvas-docker' }
|
2019-02-16 04:16:49 +08:00
|
|
|
|
2019-02-21 01:06:06 +08:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
}
|
2019-02-20 23:41:00 +08:00
|
|
|
|
2019-02-21 01:06:06 +08:00
|
|
|
environment {
|
2019-08-22 21:21:41 +08:00
|
|
|
// include selenium while smoke is running locally
|
|
|
|
COMPOSE_FILE = 'docker-compose.new-jenkins.yml:docker-compose.new-jenkins-selenium.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-08-10 06:30:33 +08:00
|
|
|
|
2019-11-16 02:12:18 +08:00
|
|
|
NAME = getImageTagVersion()
|
2019-03-15 01:44:25 +08:00
|
|
|
PATCHSET_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$NAME"
|
|
|
|
MERGE_TAG = "$DOCKER_REGISTRY_FQDN/jenkins/canvas-lms:$GERRIT_BRANCH"
|
2019-09-27 05:00:38 +08:00
|
|
|
CACHE_TAG = "canvas-lms:previous-image"
|
2019-10-16 05:12:45 +08:00
|
|
|
POSTGRES_CACHE_TAG = "canvas-lms:previous-postgres-image"
|
|
|
|
CASSANDRA_CACHE_TAG = "canvas-lms:previous-cassandra-image"
|
|
|
|
DYNAMODB_CACHE_TAG = "canvas-lms:previous-dynamodb-image"
|
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-07-29 23:55:07 +08:00
|
|
|
stage('Print Env Variables') {
|
2019-02-26 00:14:35 +08:00
|
|
|
steps {
|
2019-03-12 09:55:34 +08:00
|
|
|
timeout(time: 20, unit: 'SECONDS') {
|
2019-11-06 02:02:37 +08:00
|
|
|
sh 'printenv | sort'
|
2019-03-12 09:55:34 +08:00
|
|
|
}
|
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-11-16 02:12:18 +08:00
|
|
|
def credentials = load 'build/new-jenkins/groovy/credentials.groovy'
|
|
|
|
credentials.fetchFromGerrit('gerrit_builder', '.', '', 'canvas-lms/config')
|
2019-08-22 03:07:46 +08:00
|
|
|
gems = readFile('gerrit_builder/canvas-lms/config/plugins_list').split()
|
|
|
|
println "Plugin list: ${gems}"
|
|
|
|
/* fetch plugins */
|
2019-10-22 03:55:38 +08:00
|
|
|
gems.each { gem ->
|
|
|
|
if (env.GERRIT_PROJECT == gem) {
|
|
|
|
/* this is the commit we're testing */
|
2019-11-16 02:12:18 +08:00
|
|
|
credentials.fetchFromGerrit(gem, 'gems/plugins', null, null, env.GERRIT_REFSPEC)
|
2019-10-22 03:55:38 +08:00
|
|
|
} else {
|
2019-11-16 02:12:18 +08:00
|
|
|
credentials.fetchFromGerrit(gem, 'gems/plugins')
|
2019-10-22 03:55:38 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-16 02:12:18 +08:00
|
|
|
credentials.fetchFromGerrit('qti_migration_tool', 'vendor', 'QTIMigrationTool')
|
2019-08-22 03:07:46 +08:00
|
|
|
sh '''
|
|
|
|
mv gerrit_builder/canvas-lms/config/* config/
|
2019-08-30 21:47:07 +08:00
|
|
|
mv config/knapsack_rspec_report.json ./
|
2019-08-31 00:55:25 +08:00
|
|
|
rm config/cache_store.yml
|
2019-08-22 03:07:46 +08:00
|
|
|
rmdir -p gerrit_builder/canvas-lms/config
|
|
|
|
cp docker-compose/config/selenium.yml config/
|
2019-09-21 00:58:27 +08:00
|
|
|
cp -R docker-compose/config/new-jenkins config/new-jenkins
|
2019-08-30 21:47:07 +08:00
|
|
|
cp config/delayed_jobs.yml.example config/delayed_jobs.yml
|
|
|
|
cp config/domain.yml.example config/domain.yml
|
|
|
|
cp config/external_migration.yml.example config/external_migration.yml
|
|
|
|
cp config/outgoing_mail.yml.example config/outgoing_mail.yml
|
2019-08-22 03:07:46 +08:00
|
|
|
'''
|
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) {
|
2019-09-04 03:29:25 +08:00
|
|
|
script {
|
2019-11-16 02:12:18 +08:00
|
|
|
def credentials = load 'build/new-jenkins/groovy/credentials.groovy'
|
|
|
|
credentials.withGerritCredentials({ ->
|
2019-09-04 03:29:25 +08:00
|
|
|
sh '''
|
|
|
|
GIT_SSH_COMMAND='ssh -i \"$SSH_KEY_PATH\" -l \"$SSH_USERNAME\"' \
|
|
|
|
git fetch origin $GERRIT_BRANCH
|
|
|
|
|
2019-09-27 06:33:42 +08:00
|
|
|
git config user.name "$GERRIT_EVENT_ACCOUNT_NAME"
|
|
|
|
git config user.email "$GERRIT_EVENT_ACCOUNT_EMAIL"
|
2019-09-04 03:29:25 +08:00
|
|
|
|
|
|
|
# this helps current build issues where cleanup is needed before proceeding.
|
|
|
|
# however the later git rebase --abort should be enough once this has
|
|
|
|
# been on jenkins for long enough to hit all nodes, maybe a couple days?
|
|
|
|
if [ -d .git/rebase-merge ]; then
|
|
|
|
echo "A previous build's rebase failed and the build exited without cleaning up. Aborting the previous rebase now..."
|
|
|
|
git rebase --abort
|
2019-09-12 05:38:18 +08:00
|
|
|
git checkout $GERRIT_REFSPEC
|
2019-09-04 03:29:25 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# store exit_status inline to ensures the script doesn't exit here on failures
|
|
|
|
git rebase --preserve-merges origin/$GERRIT_BRANCH; exit_status=$?
|
|
|
|
if [ $exit_status != 0 ]; then
|
|
|
|
echo "Warning: Rebase couldn't resolve changes automatically, please resolve these conflicts locally."
|
|
|
|
git rebase --abort
|
|
|
|
exit $exit_status
|
|
|
|
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-11-16 02:12:18 +08:00
|
|
|
runBuildImageMaybe(false) {
|
2019-10-31 23:22:09 +08:00
|
|
|
timeout(time: 36) { /* this timeout is `2 * average build time` which currently: 18m * 2 = 36m */
|
|
|
|
dockerCacheLoad(image: "$CACHE_TAG")
|
|
|
|
sh '''
|
|
|
|
docker build -t $PATCHSET_TAG .
|
|
|
|
docker tag $PATCHSET_TAG $CACHE_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-07-29 23:55:07 +08:00
|
|
|
stage('Publish Patchset Image') {
|
2019-03-20 23:16:16 +08:00
|
|
|
steps {
|
2019-11-16 02:12:18 +08:00
|
|
|
runBuildImageMaybe(true) {
|
2019-10-31 23:22:09 +08:00
|
|
|
timeout(time: 5) {
|
|
|
|
// always push the patchset tag otherwise when a later
|
|
|
|
// patchset is merged this patchset tag is overwritten
|
|
|
|
sh 'docker push $PATCHSET_TAG'
|
|
|
|
}
|
2019-07-29 23:55:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Parallel Run Tests') {
|
|
|
|
parallel {
|
2019-08-15 02:43:09 +08:00
|
|
|
// TODO: this is temporary until we can get some actual builds passing
|
|
|
|
stage('Smoke Test') {
|
|
|
|
steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
skipIfPreviouslySuccessful("smoke-test") {
|
|
|
|
timeout(time: 10) {
|
2019-10-16 05:12:45 +08:00
|
|
|
script {
|
|
|
|
sh 'build/new-jenkins/docker-compose-pull-selenium.sh'
|
|
|
|
def dbCommon = load 'build/new-jenkins/groovy/cache-migrations.groovy'
|
|
|
|
dbCommon.createMigrateBuildUpCached()
|
|
|
|
sh 'build/new-jenkins/smoke-test.sh'
|
|
|
|
if (env.GERRIT_EVENT_TYPE == 'change-merged') {
|
|
|
|
dbCommon.storeMigratedImages()
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 23:22:09 +08:00
|
|
|
}
|
2019-08-15 02:43:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 01:09:34 +08:00
|
|
|
|
2019-11-06 02:02:37 +08:00
|
|
|
stage('Linters') {
|
|
|
|
steps {
|
|
|
|
skipIfPreviouslySuccessful("linters") {
|
|
|
|
build(
|
|
|
|
job: 'test-suites/linters',
|
|
|
|
propagate: false,
|
|
|
|
parameters: build_parameters
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 01:09:34 +08:00
|
|
|
stage('Vendored Gems') {
|
|
|
|
steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
skipIfPreviouslySuccessful("vendored-gems") {
|
|
|
|
build(
|
|
|
|
job: 'test-suites/vendored-gems',
|
2019-11-19 02:32:31 +08:00
|
|
|
parameters: build_parameters
|
2019-10-31 23:22:09 +08:00
|
|
|
)
|
|
|
|
}
|
2019-11-08 01:09:34 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-24 04:34:22 +08:00
|
|
|
|
|
|
|
stage('JS') {
|
|
|
|
steps {
|
|
|
|
skipIfPreviouslySuccessful("js") {
|
|
|
|
// propagate set to false until we can get tests passing
|
|
|
|
build(
|
|
|
|
job: 'test-suites/JS',
|
|
|
|
propagate: false,
|
|
|
|
parameters: build_parameters
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 00:36:22 +08:00
|
|
|
|
|
|
|
stage('Contract Tests') {
|
|
|
|
steps {
|
|
|
|
skipIfPreviouslySuccessful("contract-tests") {
|
|
|
|
build(
|
|
|
|
job: 'test-suites/contract-tests',
|
|
|
|
parameters: build_parameters
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-18 04:04:26 +08:00
|
|
|
/*
|
|
|
|
* Don't run these on all patch sets until we have them ready to report results.
|
|
|
|
* Uncomment stage to run when developing.
|
|
|
|
* stage('Selenium Chrome') {
|
|
|
|
* steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
* skipIfPreviouslySuccessful("selenium-chrome") {
|
|
|
|
* // propagate set to false until we can get tests passing
|
|
|
|
* build(
|
|
|
|
* job: 'test-suites/selenium-chrome',
|
|
|
|
* propagate: false,
|
|
|
|
* parameters: build_parameters
|
|
|
|
* )
|
|
|
|
* }
|
2019-10-18 04:04:26 +08:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* stage('Rspec') {
|
|
|
|
* steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
* skipIfPreviouslySuccessful("rspec") {
|
|
|
|
* // propagate set to false until we can get tests passing
|
|
|
|
* build(
|
|
|
|
* job: 'test-suites/rspec',
|
|
|
|
* propagate: false,
|
|
|
|
* parameters: build_parameters
|
|
|
|
* )
|
|
|
|
* }
|
2019-10-18 04:04:26 +08:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* stage('Selenium Performance Chrome') {
|
|
|
|
* steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
* skipIfPreviouslySuccessful("selenium-performance-chrome") {
|
|
|
|
* // propagate set to false until we can get tests passing
|
|
|
|
* build(
|
|
|
|
* job: 'test-suites/selenium-performance-chrome',
|
|
|
|
* propagate: false,
|
|
|
|
* parameters: build_parameters
|
|
|
|
* )
|
|
|
|
* }
|
2019-10-18 04:04:26 +08:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* stage('Xbrowser') {
|
|
|
|
* steps {
|
2019-10-31 23:22:09 +08:00
|
|
|
* skipIfPreviouslySuccessful("xbrowser") {
|
|
|
|
* // propagate set to false until we can get tests passing
|
|
|
|
* build(
|
|
|
|
* job: 'test-suites/xbrowser',
|
|
|
|
* propagate: false,
|
|
|
|
* parameters: build_parameters
|
|
|
|
* )
|
|
|
|
* }
|
2019-10-18 04:04:26 +08:00
|
|
|
* }
|
2019-10-31 23:22:09 +08:00
|
|
|
* }
|
2019-10-18 04:04:26 +08:00
|
|
|
*/
|
2019-03-20 23:16:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 23:55:07 +08:00
|
|
|
stage('Publish Merged Image') {
|
2019-11-20 02:24:38 +08:00
|
|
|
when { expression { env.GERRIT_EVENT_TYPE == 'change-merged' } }
|
2019-02-21 01:06:06 +08:00
|
|
|
steps {
|
2019-11-20 02:24:38 +08:00
|
|
|
timeout(time: 10) {
|
2019-03-15 01:44:25 +08:00
|
|
|
script {
|
2019-11-20 02:24:38 +08:00
|
|
|
sh '''
|
|
|
|
docker tag $PATCHSET_TAG $MERGE_TAG
|
|
|
|
docker push $MERGE_TAG
|
|
|
|
'''
|
|
|
|
dockerCacheStore(image: "$CACHE_TAG")
|
2019-03-15 01:44:25 +08:00
|
|
|
}
|
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 {
|
2019-11-21 02:53:17 +08:00
|
|
|
failure {
|
|
|
|
script {
|
|
|
|
if ( env.GERRIT_EVENT_TYPE == 'change-merged' ) {
|
|
|
|
slackSend (channel: '#canvas_builds',
|
|
|
|
color: '#da0005',
|
|
|
|
message: "${env.JOB_NAME} failed on merge (<${env.BUILD_URL}|${env.BUILD_NUMBER}>)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 23:16:16 +08:00
|
|
|
cleanup {
|
2019-08-22 02:43:03 +08:00
|
|
|
sh 'build/new-jenkins/docker-cleanup.sh'
|
2019-03-20 23:16:16 +08:00
|
|
|
}
|
2019-03-12 09:55:34 +08:00
|
|
|
}
|
2019-02-16 04:16:49 +08:00
|
|
|
}
|
2019-10-16 05:12:45 +08:00
|
|
|
|