Skip to content
Snippets Groups Projects
Commit 160d8446 authored by Lorenzo Pagliai's avatar Lorenzo Pagliai
Browse files

[INTEGRATION][RETRIGGER] Fix in function doing MR pipelines retrigger

After a MR is merged in a 'bsp' or 'tools' group repository all MRs
of that group are being retriggered in order to avoid issues in
successive MR integrations. This retrigger was acting on retriggering
 all opened MRs, so this change introduces:
 * Check on repository if INTEGRATION variable is defined, otherwise
skip the project MRs.
 * Check on the target branch of the final integration MR and triggers
 only pipelines on MRs affecting the same branch.
 * Cleanup the print statements for better job readability.
parent 4d6cd034
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,9 @@ critical_error = (
" 2. examine why this has happened and fix it in the CI pipeline"
)
#Function necessary to retrigger the integration pipelines on the BSP
# Function necessary to retrigger the integration pipelines on the BSP
def retrigger_bsp_pipelines(
gl, group_name, ci_project
gl, group_name, ci_project, target_branch
):
bsp_vendors = {
"nxp": "nxp",
......@@ -52,20 +52,45 @@ def retrigger_bsp_pipelines(
print(f"Checking project: {project.name}")
repo = gl.projects.get(project.id)
# Get open merge requests
open_mrs = repo.mergerequests.list(state='opened')
# Retrigger pipeline execution for all open MRs
for mr in open_mrs:
print(f"Running pipeline for MR: {mr.title}")
try:
pipeline = mr.pipelines.create()
print(f"Pipeline created with ID: {pipeline.id}")
except GitlabGetError as e:
sys.exit(
"ERROR: could not trigger merge request pipeline for MR '%s': %s"
% (mr.title, e)
)
# Get the INTEGRATION variable from the project and
# if it is not present, it is not necessary to retrigger
# any integration pipeline, thus skip all other steps
try:
integration_var = repo.variables.get('INTEGRATION').value
except GitlabGetError:
print(f"INTEGRATION variable not found for project: {project.name}, skipping.")
continue
lines = integration_var.split('\n')
# Filter lines based on target branch value, we need to
# retrigger pipelines only integrating into the same
# target branch
filtered_lines = [
line for line in lines if line.split(':')[2] == target_branch
]
# Get the corresponding source branch and retrigger
# MRs pipelines
for line in filtered_lines:
source_branch = line.split(':')[0]
# Get open merge requests for the source branch
open_mrs = repo.mergerequests.list(
target_branch=source_branch, state='opened'
)
# Retrigger pipeline execution for specific MRs
for mr in open_mrs:
print(f"Running pipeline for MR: {mr.title}")
try:
pipeline = mr.pipelines.create()
print(f"Pipeline created with ID: {pipeline.id}")
except GitlabGetError as e:
sys.exit(
"ERROR: could not trigger merge request pipeline for MR '%s': %s"
% (mr.title, e)
)
def get_source_integration_requests(
project, state=None, target_branch=None, commit=None
......@@ -292,14 +317,14 @@ def main():
except GitlabGetError as e:
sys.exit("Could not get merge request: %s" % e)
print("This job is going to merge MR %s in project %s", merge_request[0], layer_project)
print(f"This job is going to merge MR {merge_request[0].web_url} in project {layer_project.path_with_namespace}")
if accept_merge_request(layer_project, merge_request[0], rebase=args.rebase):
print("Successfully merged")
else:
sys.exit(1)
# Retrigger all necessary pipeline in the BSP group
retrigger_bsp_pipelines(gitlab, args.bsp_group, args.project)
retrigger_bsp_pipelines(gitlab, args.bsp_group, args.project, args.target_branch)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment