api-cli/Jenkinsfile

48 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-07-07 14:28:13 +02:00
pipeline {
agent any
environment {
2021-07-07 14:48:11 +02:00
NPM_REGISTRY = 'https://nexus.nclazz.de/repository/npm_releases'
2021-07-07 14:28:13 +02:00
NPM_CREDENTIALS = credentials('npm-publish')
2021-07-07 16:24:00 +02:00
GIT_CREDENTIALS = credentials('jenkins_git')
2021-07-07 14:28:13 +02:00
NPM_MAIL = 'info@nclazz.de'
}
stages {
stage('Prepare') {
2021-07-07 14:51:31 +02:00
steps {
2021-07-07 15:55:07 +02:00
echo """
NPM_REGISTRY : $env.NPM_REGISTRY
NPM_MAIL : $env.NPM_MAIL
2021-07-07 14:51:31 +02:00
BRANCH : $BRANCH_NAME
2021-07-07 16:36:09 +02:00
TAG : $TAG_NAME
2021-07-07 15:55:07 +02:00
"""
sh 'npm install'
2021-07-07 16:24:00 +02:00
sh('git remote set-url origin \$(echo $GIT_URL | sed -e "s^//^//$GIT_CREDENTIALS@^")')
2021-07-07 14:51:31 +02:00
}
2021-07-07 14:28:13 +02:00
}
stage('Set Version') {
2021-07-07 16:36:09 +02:00
when {
allOf {
expression { BRANCH_NAME == 'master' }
expression { !(TAG_NAME =~ /v*/) }
}
}
2021-07-07 14:28:13 +02:00
steps {
2021-07-07 16:15:16 +02:00
sh 'npm version patch -f'
2021-07-07 16:25:12 +02:00
sh 'git push origin HEAD:master --follow-tags --force'
2021-07-07 14:28:13 +02:00
}
}
stage('Deploy') {
2021-07-07 16:02:58 +02:00
when { tag 'v*' }
2021-07-07 14:28:13 +02:00
steps {
2021-07-07 15:55:07 +02:00
sh 'npx npm-cli-login -u $NPM_CREDENTIALS_USR -p $NPM_CREDENTIALS_PSW -e $NPM_MAIL -r $NPM_REGISTRY'
2021-07-07 14:28:13 +02:00
sh 'npm publish'
sh 'npm logout --registry=$NPM_REGISTRY'
}
}
}
2021-07-07 15:55:07 +02:00
post {
always {
cleanWs()
}
}
2021-07-07 14:28:13 +02:00
}