api-cli/Jenkinsfile

59 lines
1.8 KiB
Groovy

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 : $env.TAG_NAME
"""
sh 'npm install'
sh('git remote set-url origin \$(echo $GIT_URL | sed -e "s^//^//$GIT_CREDENTIALS@^")')
}
}
stage('Checks') {
steps {
sh 'npm run test'
}
}
stage('Set Version') {
when {
allOf {
expression { BRANCH_NAME == 'master' }
expression { env.TAG_NAME == null }
}
}
steps {
sh 'npm version patch -f'
sh 'git push origin HEAD:master --follow-tags --force'
}
}
stage('Deploy') {
when {
allOf {
expression { BRANCH_NAME == 'master' }
expression { env.TAG_NAME != null }
}
}
steps {
sh 'npx npm-cli-login -u $NPM_CREDENTIALS_USR -p $NPM_CREDENTIALS_PSW -e $NPM_MAIL -r $NPM_REGISTRY'
sh 'npm publish'
}
}
}
post {
always {
cleanWs()
}
}
}