|
1 | | -# import os |
2 | | -# import sys |
3 | | -# from multiprocessing import Process |
4 | | -# from trigger_pipelines import AzureDevOps |
| 1 | +import os |
| 2 | +import sys |
| 3 | +from multiprocessing import Process |
| 4 | +from trigger_pipelines import AzureDevOps |
5 | 5 |
|
6 | 6 |
|
7 | | -# PULL_REQUEST_PIPELINES = { |
8 | | -# "identity-service": { |
9 | | -# "build": 27, |
10 | | -# "pr": 54, |
11 | | -# "branch": "refs/heads/master" |
12 | | -# }, |
13 | | -# "canary-api": { |
14 | | -# "build": 222, |
15 | | -# "pr": 223, |
16 | | -# "branch": "refs/heads/main" |
17 | | -# }, |
18 | | -# "personal-demographics-service": { |
19 | | -# "build": 140, |
20 | | -# "pr": 144, |
21 | | -# "branch": "refs/heads/master" |
22 | | -# }, |
23 | | -# } |
| 7 | +PULL_REQUEST_PIPELINES = { |
| 8 | + "identity-service": { |
| 9 | + "build": 27, |
| 10 | + "pr": 54, |
| 11 | + "branch": "refs/heads/master" |
| 12 | + }, |
| 13 | + "canary-api": { |
| 14 | + "build": 222, |
| 15 | + "pr": 223, |
| 16 | + "branch": "refs/heads/main" |
| 17 | + }, |
| 18 | + "personal-demographics-service": { |
| 19 | + "build": 140, |
| 20 | + "pr": 144, |
| 21 | + "branch": "refs/heads/master" |
| 22 | + }, |
| 23 | +} |
24 | 24 |
|
25 | 25 |
|
26 | | -# def trigger_pipelines(pipeline_ids: dict, service: str): |
27 | | -# azure_dev_ops = AzureDevOps() |
28 | | -# build_status = azure_dev_ops.run_pipeline( |
29 | | -# service=service, |
30 | | -# pipeline_type="build", |
31 | | -# pipeline_id=pipeline_ids["build"], |
32 | | -# pipeline_branch=pipeline_ids["branch"] |
33 | | -# ) |
34 | | -# if build_status != "succeeded": |
35 | | -# sys.exit(1) |
36 | | -# return |
37 | | -# azure_dev_ops.run_pipeline( |
38 | | -# service=service, |
39 | | -# pipeline_type="pr", |
40 | | -# pipeline_id=pipeline_ids["pr"], |
41 | | -# pipeline_branch=pipeline_ids["branch"] |
42 | | -# ) |
| 26 | +def trigger_pipelines(pipeline_ids: dict, service: str): |
| 27 | + azure_dev_ops = AzureDevOps() |
| 28 | + build_status = azure_dev_ops.run_pipeline( |
| 29 | + service=service, |
| 30 | + pipeline_type="build", |
| 31 | + pipeline_id=pipeline_ids["build"], |
| 32 | + pipeline_branch=pipeline_ids["branch"] |
| 33 | + ) |
| 34 | + if build_status != "succeeded": |
| 35 | + sys.exit(1) |
| 36 | + return |
| 37 | + azure_dev_ops.run_pipeline( |
| 38 | + service=service, |
| 39 | + pipeline_type="pr", |
| 40 | + pipeline_id=pipeline_ids["pr"], |
| 41 | + pipeline_branch=pipeline_ids["branch"] |
| 42 | + ) |
43 | 43 |
|
44 | 44 |
|
45 | | -# def main(): |
46 | | -# jobs = [] |
47 | | -# for service, pipeline_ids in PULL_REQUEST_PIPELINES.items(): |
48 | | -# process = Process( |
49 | | -# target=trigger_pipelines, |
50 | | -# args=(pipeline_ids, service,) |
51 | | -# ) |
52 | | -# process.start() |
53 | | -# jobs.append(process) |
54 | | -# for process in jobs: |
55 | | -# process.join() |
56 | | -# # check return code of jobs and fail if there is a problem |
57 | | -# for process in jobs: |
58 | | -# if process.exitcode != 0: |
59 | | -# print("A job failed") |
60 | | -# sys.exit(1) |
61 | | -# sys.exit(0) |
| 45 | +def main(): |
| 46 | + jobs = [] |
| 47 | + for service, pipeline_ids in PULL_REQUEST_PIPELINES.items(): |
| 48 | + process = Process( |
| 49 | + target=trigger_pipelines, |
| 50 | + args=(pipeline_ids, service,) |
| 51 | + ) |
| 52 | + process.start() |
| 53 | + jobs.append(process) |
| 54 | + for process in jobs: |
| 55 | + process.join() |
| 56 | + # check return code of jobs and fail if there is a problem |
| 57 | + for process in jobs: |
| 58 | + if process.exitcode != 0: |
| 59 | + print("A job failed") |
| 60 | + sys.exit(1) |
| 61 | + sys.exit(0) |
62 | 62 |
|
63 | 63 |
|
64 | | -# if __name__ == "__main__": |
65 | | -# main() |
| 64 | +if __name__ == "__main__": |
| 65 | + main() |
0 commit comments