Skip to content

Commit bc45edb

Browse files
authored
Merge pull request #522 from cmu-delphi/feature-jenkins-deployments
Add new Jenkins deployment workflow
2 parents 4a36c58 + d007201 commit bc45edb

File tree

4 files changed

+108
-59
lines changed

4 files changed

+108
-59
lines changed

Jenkinsfile

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,72 @@
11
#!groovy
22

3-
// import shared library: https://github.com/cmu-delphi/jenkins-shared-library
3+
// Import shared lib.
44
@Library('jenkins-shared-library') _
55

6-
pipeline {
6+
/*
7+
Declare variables.
8+
- indicator_list should contain all the indicators to handle in the pipeline.
9+
- Keep in sync with '.github/workflows/python-ci.yml'.
10+
- TODO: #527 Get this list automatically from python-ci.yml at runtime.
11+
*/
12+
def indicator_list = ["cdc_covidnet", "claims_hosp", "combo_cases_and_deaths", "google_symptoms", "jhu", "nchs_mortality", "quidel", "quidel_covidtest", "safegraph", "safegraph_patterns", "usafacts"]
13+
def build_package = [:]
14+
def deploy_staging = [:]
15+
def deploy_production = [:]
716

17+
pipeline {
818
agent any
9-
1019
stages {
11-
12-
stage ("Environment") {
20+
stage('Build and Package') {
1321
when {
14-
anyOf {
15-
branch "deploy-*";
16-
changeRequest target: "deploy-*", comparator: "GLOB"
17-
}
22+
branch "main";
1823
}
1924
steps {
2025
script {
21-
// Get the indicator name from the pipeline env.
22-
if ( env.CHANGE_TARGET ) {
23-
INDICATOR = env.CHANGE_TARGET.replaceAll("deploy-", "")
26+
indicator_list.each { indicator ->
27+
build_package[indicator] = {
28+
sh "jenkins/build-and-package.sh ${indicator}"
29+
}
2430
}
25-
else if ( env.BRANCH_NAME ) {
26-
INDICATOR = env.BRANCH_NAME.replaceAll("deploy-", "")
27-
}
28-
else {
29-
INDICATOR = ""
30-
}
31-
}
32-
}
33-
}
34-
35-
stage('Build') {
36-
when {
37-
changeRequest target: "deploy-*", comparator: "GLOB"
38-
}
39-
steps {
40-
sh "jenkins/${INDICATOR}-jenkins-build.sh"
41-
}
42-
}
43-
44-
stage('Test') {
45-
when {
46-
changeRequest target: "deploy-*", comparator: "GLOB"
47-
}
48-
steps {
49-
sh "jenkins/${INDICATOR}-jenkins-test.sh"
50-
}
51-
}
52-
53-
stage('Package') {
54-
when {
55-
changeRequest target: "deploy-*", comparator: "GLOB"
56-
}
57-
steps {
58-
sh "jenkins/${INDICATOR}-jenkins-package.sh"
31+
parallel build_package
32+
}
5933
}
6034
}
61-
62-
stage('Deploy to staging env') {
35+
stage('Deploy staging') {
6336
when {
64-
changeRequest target: "deploy-*", comparator: "GLOB"
37+
branch "main";
6538
}
6639
steps {
67-
sh "jenkins/jenkins-deploy-staging.sh ${INDICATOR}"
40+
script {
41+
indicator_list.each { indicator ->
42+
deploy_staging[indicator] = {
43+
sh "jenkins/deploy-staging.sh ${indicator}"
44+
}
45+
}
46+
parallel deploy_staging
47+
}
6848
}
6949
}
70-
71-
stage('Deploy') {
50+
stage('Deploy production') {
7251
when {
73-
branch "deploy-*"
52+
branch "prod";
7453
}
7554
steps {
76-
sh "jenkins/${INDICATOR}-jenkins-deploy.sh"
55+
script {
56+
indicator_list.each { indicator ->
57+
deploy_production[indicator] = {
58+
sh "jenkins/deploy-production.sh ${indicator}"
59+
}
60+
}
61+
parallel deploy_production
62+
}
7763
}
7864
}
7965
}
80-
8166
post {
8267
always {
8368
script {
84-
/*
85-
Use slackNotifier.groovy from shared library and provide current
86-
build result as parameter.
87-
*/
69+
// Use slackNotifier.groovy from shared lib.
8870
slackNotifier(currentBuild.currentResult)
8971
}
9072
}

jenkins/build-and-package.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Jenkins build-and-package
4+
#
5+
6+
set -eo pipefail
7+
source ~/.bash_profile
8+
9+
# Vars
10+
local_indicator=$1
11+
12+
#
13+
# Build
14+
#
15+
16+
cd "${WORKSPACE}/${local_indicator}" || exit
17+
18+
# Set up venv
19+
python -m venv env
20+
source env/bin/activate
21+
pip install ../_delphi_utils_python/.
22+
pip install .
23+
24+
#
25+
# Package
26+
#
27+
28+
cd "${WORKSPACE}" || exit
29+
30+
# Create .tar.gz for deployment
31+
tar -czvf "${JENKINS_HOME}/artifacts/${local_indicator}.tar.gz" "${local_indicator}"

jenkins/deploy-production.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Jenkins deploy
4+
#
5+
6+
set -eo pipefail
7+
source ~/.bash_profile
8+
9+
#
10+
# Deploy
11+
#
12+
13+
local_indicator=$1
14+
15+
cd "${WORKSPACE}/ansible" || exit
16+
17+
# Ansible!
18+
ansible-playbook ansible-deploy.yaml --extra-vars "indicator=${local_indicator}" -i inventory

jenkins/deploy-staging.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Jenkins deploy
4+
#
5+
6+
set -eo pipefail
7+
source ~/.bash_profile
8+
9+
#
10+
# Deploy
11+
#
12+
13+
local_indicator=$1
14+
15+
cd "${WORKSPACE}/ansible" || exit
16+
17+
# Ansible!
18+
ansible-playbook ansible-deploy-staging.yaml --extra-vars "indicator=${local_indicator}" -i inventory

0 commit comments

Comments
 (0)