pipeline { agent any environment { NPM_REGISTRY = 'https://nexus.nclazz.de/repository/npm_releases' NPM_CREDENTIALS = credentials('npm-publish') GIT_CREDENTIALS = credentials('jenkins_git') NPM_MAIL = 'info@nclazz.de' TAG_NAME = sh(script: "git fetch --all --tags -q && git describe --tags --exact-match 2> /dev/null || echo ''", returnStdout: true).trim() } stages { stage('Prepare') { steps { echo """ NPM_REGISTRY : $env.NPM_REGISTRY NPM_MAIL : $env.NPM_MAIL BRANCH_NAME : $BRANCH_NAME TAG_NAME : $TAG_NAME """ sh 'npm install' sh('git remote set-url origin \$(echo $GIT_URL | sed -e "s^//^//$GIT_CREDENTIALS@^")') } } stage('Set Version') { when { allOf { expression { BRANCH_NAME == 'master' } expression { !(TAG_NAME =~ /v*/) } } } steps { sh 'npm version patch -f' sh 'git push origin HEAD:master --follow-tags --force' } } stage('Deploy') { when { tag 'v*' } steps { sh 'npx npm-cli-login -u $NPM_CREDENTIALS_USR -p $NPM_CREDENTIALS_PSW -e $NPM_MAIL -r $NPM_REGISTRY' sh 'npm publish' sh 'npm logout --registry=$NPM_REGISTRY' } } } post { always { cleanWs() } } }