2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> npm-config.sh"
13 # Configure a custom hosted npm registry and / or https://registry.npmjs.org/
15 # $NPM_REGISTRY : Required
16 # Jenkins global variable should be defined
17 # If set, then this is the base IP or FQDN that will be used
18 # for logging into the custom npm registry
19 # ex: $NPM_URL/repository/npm.snapshot/
20 # wereh NPM_URL is defined as a global env var in Jenkins.
21 # $NPM_SERVER_ID: Required
22 # The id of the server as specified in the global-settings file
23 # Typically this is settings.xml
24 # $SETTINGS_FILE: Required
25 # Job level variable with maven settings file location
28 # Ensure we fail the job if any steps fail
31 # Execute the credential lookup and login to the registry
34 CREDENTIAL=$(xmlstarlet sel -N "x=http://maven.apache.org/SETTINGS/1.0.0" \
35 -t -m "/x:settings/x:servers/x:server[starts-with(x:id, '${NPM_SERVER_ID}')]" \
36 -v x:username -o ":" -v x:password \
39 USER=$(echo "$CREDENTIAL" | cut -f1 -d:)
40 PASS=$(echo "$CREDENTIAL" | cut -f2 -d:)
44 echo "ERROR: No user provided"
50 echo "ERROR: No password provided"
55 auth_token=$(echo -n "$USER":"$PASS" | openssl base64)
58 echo "//$NPM_REGISTRY:_auth$auth_token" >> "$HOME/.npmrc"