diff --git a/Jenkinsfile b/Jenkinsfile index 19b04d4..8f232d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,19 +66,20 @@ pipeline { -e HOME=/tmp \ -e NPM_CONFIG_CACHE=/npm-cache \ -e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \ + -e NPM_LOCK_HASH_FILE=${NPM_LOCK_HASH_FILE} \ -v ${NPM_CACHE_VOLUME}:/npm-cache \ -v ${NODE_MODULES_VOLUME}:/workspace/node_modules \ ${CI_IMAGE} \ - sh -lc "cd /workspace && \ - lock_hash=\$(sha256sum package-lock.json | cut -d ' ' -f1) && \ - cached_hash=\$(cat ${NPM_LOCK_HASH_FILE} 2>/dev/null || true) && \ - if [ \"\$lock_hash\" = \"\$cached_hash\" ] && [ -d node_modules ] && [ \"\$(ls -A node_modules 2>/dev/null)\" ]; then \ - echo 'node_modules cache hit, skip npm ci'; \ + sh -lc 'set -e; cd /workspace; \ + lock_hash=$(sha256sum package-lock.json | cut -d " " -f1); \ + cached_hash=$(cat "$NPM_LOCK_HASH_FILE" 2>/dev/null || true); \ + if [ "$lock_hash" = "$cached_hash" ] && [ -d node_modules ] && [ "$(ls -A node_modules 2>/dev/null)" ]; then \ + echo "node_modules cache hit, skip npm ci"; \ else \ - npm ci --prefer-offline --no-audit --progress=false && \ - echo \"\$lock_hash\" > ${NPM_LOCK_HASH_FILE}; \ - fi && \ - npm run lint && npx tsc --noEmit && npm run test:coverage && npm run test:e2e:smoke") + npm ci --prefer-offline --no-audit --progress=false; \ + printf "%s" "$lock_hash" > "$NPM_LOCK_HASH_FILE"; \ + fi; \ + npm run lint; npx tsc --noEmit; npm run test:coverage; npm run test:e2e:smoke') cleanup() { docker rm -f "$cid" >/dev/null 2>&1 || true } @@ -152,19 +153,20 @@ pipeline { -e HOME=/tmp \ -e NPM_CONFIG_CACHE=/npm-cache \ -e NPM_CONFIG_REGISTRY=${NPM_REGISTRY} \ + -e NPM_LOCK_HASH_FILE=${NPM_LOCK_HASH_FILE} \ -v ${NPM_CACHE_VOLUME}:/npm-cache \ -v ${NODE_MODULES_VOLUME}:/workspace/node_modules \ ${CI_IMAGE} \ - sh -lc "cd /workspace && \ - lock_hash=\$(sha256sum package-lock.json | cut -d ' ' -f1) && \ - cached_hash=\$(cat ${NPM_LOCK_HASH_FILE} 2>/dev/null || true) && \ - if [ \"\$lock_hash\" = \"\$cached_hash\" ] && [ -d node_modules ] && [ \"\$(ls -A node_modules 2>/dev/null)\" ]; then \ - echo 'node_modules cache hit, skip npm ci'; \ + sh -lc 'set -e; cd /workspace; \ + lock_hash=$(sha256sum package-lock.json | cut -d " " -f1); \ + cached_hash=$(cat "$NPM_LOCK_HASH_FILE" 2>/dev/null || true); \ + if [ "$lock_hash" = "$cached_hash" ] && [ -d node_modules ] && [ "$(ls -A node_modules 2>/dev/null)" ]; then \ + echo "node_modules cache hit, skip npm ci"; \ else \ - npm ci --prefer-offline --no-audit --progress=false && \ - echo \"\$lock_hash\" > ${NPM_LOCK_HASH_FILE}; \ - fi && \ - npm run test:e2e") + npm ci --prefer-offline --no-audit --progress=false; \ + printf "%s" "$lock_hash" > "$NPM_LOCK_HASH_FILE"; \ + fi; \ + npm run test:e2e') cleanup() { docker rm -f "$cid" >/dev/null 2>&1 || true }