fix: Use HELM specific netrc builder 46/123046/1
authorJessica Wagantall <jwagantall@linuxfoundation.org>
Tue, 3 Aug 2021 03:19:36 +0000 (20:19 -0700)
committerJessica Wagantall <jwagantall@linuxfoundation.org>
Tue, 3 Aug 2021 03:19:36 +0000 (20:19 -0700)
We need a local create-netrc builder that
allows us to create an entry for the helm repo
which is hosted in Nexus3.

Issue-ID: CIMAN-33
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Change-Id: Ic14ea2dc7910d6422872c3c0af94c01b77d7dc20

jjb/global-templates-helm.yaml
shell/oom-create-netrc.sh [new file with mode: 0644]

index 25e3921..0e5986a 100644 (file)
@@ -1,4 +1,15 @@
 ---
+############
+# BUILDERS #
+############
+
+- builder:
+    name: oom-create-netrc
+    builders:
+      - inject:
+          properties-content: "SERVER_ID={server-id}"
+      - shell: !include-raw-escape: ../shell/oom-create-netrc.sh
+
 ###########
 # ANCHORS #
 ###########
           echo "export HELM_BIN=helm3.5" > helm.prop
       - shell: '{obj:pre_build_script}'
       - shell: '{obj:build_script}'
-      - lf-infra-create-netrc:
+      - oom-create-netrc:
           server-id: oom-helm
       - inject:
           properties-content: |
diff --git a/shell/oom-create-netrc.sh b/shell/oom-create-netrc.sh
new file mode 100644 (file)
index 0000000..4b076a6
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2017 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> oom-create-netrc.sh"
+
+if [ -z "$ALT_DOCKER_URL" ]; then
+    DOCKER_URL="${DOCKER_REGISTRY:-$DOCKER_URL}"
+else
+    DOCKER_URL="${ALT_DOCKER_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")
+
+# 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 "$DOCKER_URL" | awk -F/ '{print $3}')
+fi
+
+user=$(echo "$CREDENTIAL" | cut -f1 -d:)
+pass=$(echo "$CREDENTIAL" | cut -f2 -d:)
+
+set +x  # Disable `set -x` to prevent printing passwords
+echo "machine ${machine%:*} login $user password $pass" >> ~/.netrc