Skip to content

Commit

Permalink
Fix auth in release.py for nightly: right handle --auth values in Jen…
Browse files Browse the repository at this point in the history
…kins calss (#1217)

* Return errors on calls to Jenkins
* Add type hints to call_jenkins_build
* Fix auth problems with credentials

---------
Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
  • Loading branch information
j-rivero authored Nov 29, 2024
1 parent bc7d636 commit 0a66f6c
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -535,19 +535,21 @@ 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' ")
username, api_token = auth_input_arg.split(':')
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,
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 0a66f6c

Please sign in to comment.