|
1 | 1 | #!groovy |
2 | 2 |
|
3 | | -// import shared library: https://github.com/cmu-delphi/jenkins-shared-library |
| 3 | +// Import shared lib. |
4 | 4 | @Library('jenkins-shared-library') _ |
5 | 5 |
|
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 = [:] |
7 | 16 |
|
| 17 | +pipeline { |
8 | 18 | agent any |
9 | | - |
10 | 19 | stages { |
11 | | - |
12 | | - stage ("Environment") { |
| 20 | + stage('Build and Package') { |
13 | 21 | when { |
14 | | - anyOf { |
15 | | - branch "deploy-*"; |
16 | | - changeRequest target: "deploy-*", comparator: "GLOB" |
17 | | - } |
| 22 | + branch "main"; |
18 | 23 | } |
19 | 24 | steps { |
20 | 25 | 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 | + } |
24 | 30 | } |
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 | + } |
59 | 33 | } |
60 | 34 | } |
61 | | - |
62 | | - stage('Deploy to staging env') { |
| 35 | + stage('Deploy staging') { |
63 | 36 | when { |
64 | | - changeRequest target: "deploy-*", comparator: "GLOB" |
| 37 | + branch "main"; |
65 | 38 | } |
66 | 39 | 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 | + } |
68 | 48 | } |
69 | 49 | } |
70 | | - |
71 | | - stage('Deploy') { |
| 50 | + stage('Deploy production') { |
72 | 51 | when { |
73 | | - branch "deploy-*" |
| 52 | + branch "prod"; |
74 | 53 | } |
75 | 54 | 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 | + } |
77 | 63 | } |
78 | 64 | } |
79 | 65 | } |
80 | | - |
81 | 66 | post { |
82 | 67 | always { |
83 | 68 | 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. |
88 | 70 | slackNotifier(currentBuild.currentResult) |
89 | 71 | } |
90 | 72 | } |
|
0 commit comments