Skip to content

Commit 936a4d5

Browse files
authored
Merge pull request #2005 from cmu-delphi/refactor-jenkins-pipeline
Refactor Jenkins pipeline
2 parents f11ca4e + 9dc3c43 commit 936a4d5

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

Jenkinsfile

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- TODO: #527 Get this list automatically from python-ci.yml at runtime.
1111
*/
1212

13-
def indicator_list = ["backfill_corrections", "changehc", "claims_hosp", "google_symptoms", "hhs_hosp", "nchs_mortality", "quidel_covidtest", "sir_complainsalot", "doctor_visits", "nwss_wastewater", "nssp"]
13+
def indicator_list = ['backfill_corrections', 'changehc', 'claims_hosp', 'google_symptoms', 'hhs_hosp', 'nchs_mortality', 'quidel_covidtest', 'sir_complainsalot', 'doctor_visits', 'nwss_wastewater', 'nssp']
1414
def build_package_main = [:]
1515
def build_package_prod = [:]
1616
def deploy_staging = [:]
@@ -19,39 +19,62 @@ def deploy_production = [:]
1919
pipeline {
2020
agent any
2121
stages {
22-
stage('Build and Package main') {
22+
stage('Build dev/feature branch') {
23+
when {
24+
not {
25+
anyOf {
26+
branch 'main'
27+
branch 'prod'
28+
}
29+
}
30+
}
31+
steps {
32+
script {
33+
indicator_list.each { indicator ->
34+
stage("Build ${indicator}") {
35+
sh "jenkins/build-indicator.sh ${indicator}"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
stage('Build and Package main branch') {
2342
when {
24-
branch "main";
43+
branch 'main'
2544
}
2645
steps {
2746
script {
2847
indicator_list.each { indicator ->
29-
build_package_main[indicator] = {
30-
sh "jenkins/build-and-package.sh ${indicator} main"
48+
stage("Build ${indicator}") {
49+
sh "jenkins/build-indicator.sh ${indicator}"
50+
}
51+
stage("Package ${indicator}") {
52+
sh "jenkins/package-indicator.sh ${indicator} main"
3153
}
3254
}
33-
parallel build_package_main
3455
}
3556
}
3657
}
37-
stage('Build and Package prod') {
58+
stage('Build and Package prod branch') {
3859
when {
39-
branch "prod";
60+
branch 'prod'
4061
}
4162
steps {
4263
script {
4364
indicator_list.each { indicator ->
44-
build_package_prod[indicator] = {
45-
sh "jenkins/build-and-package.sh ${indicator} prod"
65+
stage("Build ${indicator}") {
66+
sh "jenkins/build-indicator.sh ${indicator}"
67+
}
68+
stage("Package ${indicator}") {
69+
sh "jenkins/package-indicator.sh ${indicator} prod"
4670
}
4771
}
48-
parallel build_package_prod
4972
}
5073
}
5174
}
52-
stage('Deploy staging') {
75+
stage('Deploy main branch to staging env') {
5376
when {
54-
branch "main";
77+
branch 'main'
5578
}
5679
steps {
5780
script {
@@ -64,9 +87,9 @@ pipeline {
6487
}
6588
}
6689
}
67-
stage('Deploy production') {
90+
stage('Deploy prod branch to production env') {
6891
when {
69-
branch "prod";
92+
branch 'prod'
7093
}
7194
steps {
7295
script {
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#!/usr/bin/env bash
22
#
3-
# Jenkins build-and-package
3+
# Jenkins build
44
#
55

66
set -eo pipefail
77
source ~/.bash_profile
88

99
# Vars
1010
local_indicator=$1
11-
branch=$2
12-
13-
#
14-
# Build
15-
#
1611

1712
cd "${WORKSPACE}/${local_indicator}" || exit
1813

@@ -23,12 +18,3 @@ pip install pip==23.0.1 --retries 10 --timeout 20
2318
pip install numpy --retries 10 --timeout 20
2419
pip install ../_delphi_utils_python/. --retries 10 --timeout 20
2520
[ ! -f setup.py ] || pip install . --retries 10 --timeout 20
26-
27-
#
28-
# Package
29-
#
30-
31-
cd "${WORKSPACE}" || exit
32-
33-
# Create .tar.gz for deployment
34-
tar -czvf "${JENKINS_HOME}/artifacts/${branch}_${local_indicator}.tar.gz" "${local_indicator}"

jenkins/package-indicator.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Jenkins package
4+
#
5+
6+
set -eo pipefail
7+
source ~/.bash_profile
8+
9+
# Vars
10+
local_indicator=$1
11+
branch=$2
12+
13+
cd "${WORKSPACE}" || exit
14+
15+
# Create .tar.gz for deployment
16+
tar -czvf "${JENKINS_HOME}/artifacts/${branch}_${local_indicator}.tar.gz" "${local_indicator}"

0 commit comments

Comments
 (0)