From: Thanh Ha Date: Tue, 27 Jun 2017 03:38:29 +0000 (-0400) Subject: Deploy to Nexus using parallel X-Git-Tag: v0.5.0~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=4da2d409ff0863f776f5680f31cb6cc1aeed3be2;p=releng%2Flftools.git Deploy to Nexus using parallel Speed up the script by using GNU parallel to push when it is available. Change-Id: I8ddff8b8cf50cd821aae21958ab8b5c7ecc33174 Signed-off-by: Thanh Ha --- diff --git a/shell/deploy b/shell/deploy index b25d4397..e330a95a 100755 --- a/shell/deploy +++ b/shell/deploy @@ -508,19 +508,14 @@ deploy_nexus() { ! -name resolver-status.properties \ | cut -c 3-)) - for file in "${file_list[@]}"; do - echo "Uploading ${file}" - - local resp - resp=$(curl -s -w "%{http_code}" --netrc --upload-file "$file" "$nexus_repo_url/$file") - status=$(echo "$resp" | awk 'END {print $NF}') - - if [ "$status" != "201" ]; then - echo "ERROR: Failed to upload to Nexus. Aborting..." - echo "$resp" - exit "$status" - fi - done + if hash parallel 2>/dev/null; then + export -f upload_to_nexus + parallel --jobs 200% --halt now,fail=1 "upload_to_nexus $nexus_repo_url {}" ::: ${file_list[*]} + else + for file in "${file_list[@]}"; do + upload_to_nexus "$nexus_repo_url" "$file" + done + fi popd } @@ -631,6 +626,30 @@ deploy_nexus_zip() { "${nexus_url}/service/local/repositories/${nexus_repo}/content-compressed/${nexus_path}" } +upload_to_nexus() { + # Helper function to push a file to Nexus via cURL + # + # Parameters: + # + # nexus_repo_url: The URL to the Nexus repo. + # (Ex: https://nexus.example.org/content/repositories/release) + # file: File that is to be pushed to Nexus. + local nexus_repo_url="$1" + local file="$2" + + echo "Uploading ${file}" + + local resp + resp=$(curl -s -w "%{http_code}" --netrc --upload-file "$file" "$nexus_repo_url/$file") + status=$(echo "$resp" | awk 'END {print $NF}') + + if [ "$status" != "201" ]; then + echo "ERROR: Failed to upload to Nexus. Aborting..." + echo "$resp" + exit "$status" + fi +} + # Only run the script if it is being called directly and not sourced. if [[ "${BASH_SOURCE[0]}" == "${0}" ]] then