2018-06-11 22:50:44 +03:00
|
|
|
@Library('github.com/mozmeao/jenkins-pipeline@20171123.1')
|
2017-11-22 14:23:09 +03:00
|
|
|
def config
|
|
|
|
def docker_image
|
2018-06-07 16:56:22 +03:00
|
|
|
def dc_name
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2017-11-22 14:23:09 +03:00
|
|
|
conduit {
|
2018-06-07 16:56:22 +03:00
|
|
|
node {
|
|
|
|
stage("Prepare") {
|
|
|
|
checkout scm
|
|
|
|
setGitEnvironmentVariables()
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
try {
|
|
|
|
config = readYaml file: "jenkins.yml"
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
config = []
|
|
|
|
}
|
|
|
|
println "config ==> ${config}"
|
2016-10-31 17:10:30 +03:00
|
|
|
|
2018-06-07 16:56:22 +03:00
|
|
|
if (!config || (config && config.pipeline && config.pipeline.enabled == false)) {
|
|
|
|
println "Pipeline disabled."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
docker_image = "${config.project.docker_name}:full-${GIT_COMMIT_SHORT}"
|
2018-07-27 21:34:17 +03:00
|
|
|
sh "bin/slack-notify.sh --status starting --stage 'Build & Test'"
|
2018-06-07 16:56:22 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
stage("Build Docker Images") {
|
2018-06-07 16:56:22 +03:00
|
|
|
if (!dockerImageExists(docker_image)) {
|
2018-07-27 21:34:17 +03:00
|
|
|
try {
|
2018-10-30 22:44:11 +03:00
|
|
|
sh "make build-ci"
|
2018-07-27 21:34:17 +03:00
|
|
|
} catch(err) {
|
|
|
|
sh "bin/slack-notify.sh --status failure --stage 'Docker Build'"
|
|
|
|
throw err
|
|
|
|
}
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "Image ${docker_image} already exists."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
stage("Upload Docker Images") {
|
|
|
|
try {
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-no-locales-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:locales-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:staticfiles-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-dev-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-${GIT_COMMIT_SHORT}", "mozjenkins-docker-hub")
|
|
|
|
} catch(err) {
|
|
|
|
sh "bin/slack-notify.sh --status failure --stage 'Upload Docker Images'"
|
|
|
|
throw err
|
|
|
|
}
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
2017-11-22 14:23:09 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
stage("Run Tests") {
|
2018-06-07 16:56:22 +03:00
|
|
|
try {
|
2018-10-30 22:44:11 +03:00
|
|
|
env.COMPOSE_PROJECT_NAME = "${config.project.name}-${BUILD_NUMBER}-${GIT_COMMIT_SHORT}"
|
2018-07-27 21:34:17 +03:00
|
|
|
// flake8
|
2018-10-30 22:44:11 +03:00
|
|
|
sh "make lint-ci"
|
2018-07-27 21:34:17 +03:00
|
|
|
// mocha
|
2018-10-30 22:44:11 +03:00
|
|
|
sh "make test-js-ci"
|
2018-07-27 21:34:17 +03:00
|
|
|
// unittests
|
|
|
|
try {
|
2018-10-30 22:44:11 +03:00
|
|
|
sh "make test-ci"
|
2018-07-27 21:34:17 +03:00
|
|
|
} finally {
|
2018-10-30 22:44:11 +03:00
|
|
|
sh "docker-compose kill"
|
2018-07-27 21:34:17 +03:00
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
sh "bin/slack-notify.sh --status failure --stage 'Run Tests'"
|
|
|
|
throw err
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage("Upload Latest Images") {
|
|
|
|
// When on master branch tag and push push the latest tag
|
|
|
|
onBranch("master") {
|
2018-07-27 21:34:17 +03:00
|
|
|
try {
|
|
|
|
dockerImageTag("${config.project.docker_name}:full-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:full-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-latest", "mozjenkins-docker-hub")
|
2017-11-22 14:23:09 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:full-no-locales-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:full-no-locales-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:full-no-locales-latest", "mozjenkins-docker-hub")
|
2018-06-07 16:56:22 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:locales-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:locales-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:locales-latest", "mozjenkins-docker-hub")
|
2018-06-07 16:56:22 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:staticfiles-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:staticfiles-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:staticfiles-latest", "mozjenkins-docker-hub")
|
2018-06-07 16:56:22 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:base-dev-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-dev-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-dev-latest", "mozjenkins-docker-hub")
|
2018-06-07 16:56:22 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
dockerImageTag("${config.project.docker_name}:base-${GIT_COMMIT_SHORT}", "${config.project.docker_name}:base-latest")
|
|
|
|
dockerImagePush("${config.project.docker_name}:base-latest", "mozjenkins-docker-hub")
|
|
|
|
} catch(err) {
|
|
|
|
sh "bin/slack-notify.sh --status failure --stage 'Upload Latest Docker Images'"
|
|
|
|
throw err
|
|
|
|
}
|
2018-07-19 18:20:01 +03:00
|
|
|
|
2018-07-27 21:34:17 +03:00
|
|
|
try {
|
|
|
|
sh "docker/bin/upload-staticfiles.sh"
|
|
|
|
} catch(err) {
|
|
|
|
sh "bin/slack-notify.sh --status failure --stage 'Upload Static Files'"
|
|
|
|
throw err
|
|
|
|
}
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
|
|
|
}
|
2018-07-27 21:34:17 +03:00
|
|
|
sh "bin/slack-notify.sh --status success --stage 'Docker image ready to deploy: ${docker_image}'"
|
2018-06-07 16:56:22 +03:00
|
|
|
}
|
2016-10-31 17:10:30 +03:00
|
|
|
}
|