diff --git a/tools/ci/ci_get_latest_mr_iid.py b/tools/ci/ci_get_latest_mr_iid.py new file mode 100644 index 0000000000..0b3ed92b88 --- /dev/null +++ b/tools/ci/ci_get_latest_mr_iid.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# +# internal use only for CI +# get latest MR IID by source branch + +import argparse +import os + +from gitlab_api import Gitlab + + +def get_MR_IID_by_source_branch(source_branch): + if not source_branch: + return '' + gl = Gitlab(os.getenv('CI_PROJECT_ID')) + if not gl.project: + return '' + mrs = gl.project.mergerequests.list(state='opened', source_branch=source_branch) + if mrs: + mr = mrs[0] # one source branch can only have one opened MR at one moment + return mr.iid + return '' + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Get the latest MR IID by source branch, if not found, return empty string') + parser.add_argument('source_branch', nargs='?', help='source_branch') # won't fail if it's empty + + args = parser.parse_args() + + print(get_MR_IID_by_source_branch(args.source_branch)) diff --git a/tools/ci/config/build.yml b/tools/ci/config/build.yml index a579a977a3..cc27f2bdff 100644 --- a/tools/ci/config/build.yml +++ b/tools/ci/config/build.yml @@ -447,7 +447,11 @@ code_quality_check: - clang_tidy_check_regular only: - triggers + allow_failure: true script: + - export CI_MERGE_REQUEST_IID=`python ${CI_PROJECT_DIR}/tools/ci/ci_get_latest_mr_iid.py ${CI_COMMIT_BRANCH} | xargs` + # test if this branch have merge request, if not, exit 0 + - test -n "$CI_MERGE_REQUEST_IID" || exit 0 - sonar-scanner -Dsonar.analysis.mode=preview -Dsonar.host.url=$SONAR_HOST_URL