From 9fe097a49550a23a43e2ff66788a25fdcb761779 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 14 Nov 2023 03:35:50 +0300 Subject: [PATCH] Configure npm and yarn to use Artifactory "npm" repository --- jfrog-oauth/run.sh | 13 ++++++++++--- jfrog-token/run.sh | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 90b5bba..bc584ee 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -19,12 +19,19 @@ export CI=true jf c rm 0 || true echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 -# Configure the `npm` CLI to use the Artifactory "npm" repository. if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." else - echo "📦 Configuring npm..." - jf npmc --global --repo-resolve "${REPOSITORY_NPM}" + # check if npm is installed and configure it to use the Artifactory "npm" repository. + if command -v npm >/dev/null 2>&1; then + echo "📦 Configuring npm..." + jf npmc --global --repo-resolve "${REPOSITORY_NPM}" + fi + # check if yarn is installed and configure it to use the Artifactory "npm" repository. + if command -v yarn >/dev/null 2>&1; then + echo "📦 Configuring yarn..." + jf yarn --global --repo-resolve "${REPOSITORY_NPM}" + fi cat <~/.npmrc email = ${ARTIFACTORY_EMAIL} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 90b5bba..bc584ee 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -19,12 +19,19 @@ export CI=true jf c rm 0 || true echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0 -# Configure the `npm` CLI to use the Artifactory "npm" repository. if [ -z "${REPOSITORY_NPM}" ]; then echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." else - echo "📦 Configuring npm..." - jf npmc --global --repo-resolve "${REPOSITORY_NPM}" + # check if npm is installed and configure it to use the Artifactory "npm" repository. + if command -v npm >/dev/null 2>&1; then + echo "📦 Configuring npm..." + jf npmc --global --repo-resolve "${REPOSITORY_NPM}" + fi + # check if yarn is installed and configure it to use the Artifactory "npm" repository. + if command -v yarn >/dev/null 2>&1; then + echo "📦 Configuring yarn..." + jf yarn --global --repo-resolve "${REPOSITORY_NPM}" + fi cat <~/.npmrc email = ${ARTIFACTORY_EMAIL} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}