Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth in release.py for nightly: right handle --auth values in Jenkins calss #1217

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)