X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fcreate-netrc.sh;h=57f1f15c6e2e6bf646a0b1374778505a78605af9;hb=04547fcca5cabd3d9ad24fced4a0cf268d789296;hp=4a15e3b661c114a9a5f600538033a9cf8b118657;hpb=851b0b6d0cfe84e986548fd596a9b2f18413fefd;p=releng%2Fglobal-jjb.git diff --git a/shell/create-netrc.sh b/shell/create-netrc.sh index 4a15e3b6..57f1f15c 100644 --- a/shell/create-netrc.sh +++ b/shell/create-netrc.sh @@ -1,5 +1,5 @@ #!/bin/bash -# @License EPL-1.0 +# SPDX-License-Identifier: EPL-1.0 ############################################################################## # Copyright (c) 2017 The Linux Foundation and others. # @@ -8,15 +8,43 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################## +echo "---> create-netrc.sh" -NEXUS_URL="${NEXUS_URL:-$NEXUSPROXY}" +if [ -z "$ALT_NEXUS_URL" ]; then + NEXUS_URL="${NEXUSPROXY:-$NEXUS_URL}" +else + NEXUS_URL="${ALT_NEXUS_URL}" +fi CREDENTIAL=$(xmlstarlet sel -N "x=http://maven.apache.org/SETTINGS/1.0.0" \ -t -m "/x:settings/x:servers/x:server[x:id='${SERVER_ID}']" \ -v x:username -o ":" -v x:password \ "$SETTINGS_FILE") -machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}') +# Ensure we fail the job if any steps fail. +set -eu -o pipefail + +# Handle when a project chooses to not archive logs to a log server +# in other cases if CREDENTIAL is not found then fail the build. +if [ -z "$CREDENTIAL" ] && [ "$SERVER_ID" == "logs" ]; then + echo "WARN: Log server credential not found." + exit 0 +elif [ -z "$CREDENTIAL" ] && [ "$SERVER_ID" == "ossrh" ]; then + echo "WARN: OSSRH credentials not found." + echo " This is needed for staging to Maven Central." + exit 0 +elif [ -z "$CREDENTIAL" ]; then + echo "ERROR: Credential not found." + exit 1 +fi + +if [ "$SERVER_ID" == "ossrh" ]; then + machine="oss.sonatype.org" +else + machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}') +fi + user=$(echo "$CREDENTIAL" | cut -f1 -d:) pass=$(echo "$CREDENTIAL" | cut -f2 -d:) -echo "machine $machine login $user password $pass" > ~/.netrc +set +x # Disable `set -x` to prevent printing passwords +echo "machine ${machine%:*} login $user password $pass" >> ~/.netrc