diff --git a/release.py b/release.py index f69038eae..51927496b 100755 --- a/release.py +++ b/release.py @@ -133,7 +133,7 @@ def parse_args(argv): parser.add_argument('--dry-run', dest='dry_run', action='store_true', default=False, help='dry-run; i.e., do actually run any of the commands') parser.add_argument('--auth', dest='auth_input_arg', - default=None, + default="", help='Explicit jenkins user:token string overriding the jenkins.ini credentials file.') parser.add_argument('-a', '--package-alias', dest='package_alias', default=None, @@ -535,7 +535,8 @@ def generate_source_params(args): return params -def build_credentials_header(auth_input_arg = None): + +def build_credentials_header(auth_input_arg: str = ""): if auth_input_arg: if len(auth_input_arg.split(':')) != 2: error("Auth string is not in the form of 'user:token' ") @@ -543,11 +544,12 @@ def build_credentials_header(auth_input_arg = None): else: username, api_token = get_credentials(JENKINS_URL) if not username: - exit(1) + error("No username found in credentials file") return make_headers(basic_auth=f'{username}:{api_token}') -def check_credentials(auth_input_arg = None): + +def check_credentials(auth_input_arg: str = ""): http = urllib3.PoolManager() response = http.request('GET', JENKINS_URL, @@ -558,11 +560,11 @@ def check_credentials(auth_input_arg = None): exit(1) -def call_jenkins_build(job_name, - params, - output_string, - search_description_help, - auth_input_arg = None): +def call_jenkins_build(job_name: str, + params: dict, + output_string: str, + search_description_help: str, + auth_input_arg: str): # Only to help user feedback this block help_url = f'{JENKINS_URL}/job/{job_name}' if search_description_help: @@ -579,20 +581,22 @@ def call_jenkins_build(job_name, if not DRY_RUN: http = urllib3.PoolManager() - try : - response = http.request('POST', - url , - headers=build_credentials_header(auth_input_arg)) + try: + response = \ + http.request('POST', + url, + headers=build_credentials_header(auth_input_arg)) # 201 code is "created", it is the expected return of POST if response.status != 201: - print(f"Error {response.status}: {response.reason}") - exit(1) + http.clear() + error(f"{response.status}: {response.reason}") except RequestError as e: - print(f"An error occurred in the http request: {e}") + http.clear() + error(f"An error occurred in the http request: {e}") except Exception as e: - print(f"An unexpected error occurred: {e}") - finally: http.clear() + error(f"An unexpected error occurred: {e}") + def display_help_job_chain_for_source_calls(args): # Encode the different ways using in the job descriptions to filter builds @@ -819,8 +823,10 @@ def go(argv): # RELEASING FOR BREW if not NIGHTLY and not args.bump_rev_linux_only: call_jenkins_build(GENERIC_BREW_PULLREQUEST_JOB, - params, 'Brew', - f'{args.package_alias}-{args.version}') + params, + 'Brew', + f'{args.package_alias}-{args.version}', + args.auth_input_arg) # RELEASING FOR LINUX for l in LINUX_DISTROS: if (l == 'ubuntu'): @@ -874,7 +880,8 @@ def go(argv): call_jenkins_build(f'{package_alias_force_gz}-debbuilder', linux_platform_params, f"{l} {d}/{a}", - f"{args.version}-{args.release_version}") + f"{args.version}-{args.release_version}", + args.auth_input_arg) else: # b) Mode generate source # Choose platform to run gz-source on. It will need to install gz-cmake @@ -902,10 +909,12 @@ def go(argv): call_jenkins_build(f'{package_alias_force_gz}-source', params, 'Source', - args.version) + args.version, + args.auth_input_arg) display_help_job_chain_for_source_calls(args) # Process the possible update of an associated ROS vendor package process_ros_vendor_package(args) + if __name__ == '__main__': go(sys.argv)