Files
node-wannistesvorbei/Jenkinsfile
Sebastian Seedorf 5d456ee817 Added Jenkinsfile 15
2021-04-19 14:42:13 +02:00

127 lines
3.6 KiB
Groovy

#!groovy
/*
The MIT License
Copyright (c) 2015-, CloudBees, Inc., and a number of other of contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
node {
sh 'git rev-parse --verify HEAD > GIT_COMMIT'
env.GIT_COMMIT = readFile('GIT_COMMIT').trim().substring(0, 10)
sh 'rm GIT_COMMIT'
def jobName = env.JOB_NAME.tokenize('/')
print env.jobName
env.DOCKER_NAME="${jobName[0]}/${jobName[1]}:${env.BRANCH_NAME}-${env.GIT_COMMIT}"
env.DOCKER_REGISTRY="docker.sebse.de"
env.NODEJS_HOME = "${tool 'node14'}"
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
def customImage
currentBuild.result = "SUCCESS"
try {
stage('Checkout'){
checkout scm
}
stage('Test'){
env.NODE_ENV = "test"
print "Environment will be : ${env.NODE_ENV}"
sh 'node -v'
sh 'npm prune'
sh 'npm install'
//sh 'npm test'
}
stage('Build Prod'){
env.NODE_ENV = "production"
print "Environment will be : ${env.NODE_ENV}"
sh 'node -v'
sh 'npm prune'
sh 'npm install --production=false'
sh './node_modules/.bin/tsc'
sh 'rm node_modules -rf'
sh 'npm install --only=production'
}
stage('Build Docker'){
customImage = docker.build(env.DOCKER_NAME)
}
stage('Deploy'){
echo 'Push to Repo'
docker.withRegistry("https://${DOCKER_REGISTRY}", 'docker-registry-robot-web-development') {
/* Push the container to the custom Registry */
customImage.push()
}
/*echo 'ssh to web server and tell it to pull new image'
sh 'ssh deploy@xxxxx.xxxxx.com running/xxxxxxx/dockerRun.sh'*/
}
stage('Cleanup'){
echo 'prune and cleanup'
sh 'npm prune'
sh 'rm node_modules -rf'
sh "docker rmi ${env.DOCKER_NAME} ${DOCKER_REGISTRY}/${env.DOCKER_NAME}"
sh 'docker image prune -f'
sh 'docker rmi $(docker images -a | grep "<none>" | awk "{print \$3}") &2>/del/null || exit 0'
/*mail body: 'project build successful',
from: 'xxxx@yyyyy.com',
replyTo: 'xxxx@yyyy.com',
subject: 'project build successful',
to: 'yyyyy@yyyy.com'*/
}
}
catch (err) {
currentBuild.result = "FAILURE"
/*mail body: "project build error is here: ${env.BUILD_URL}" ,
from: 'xxxx@yyyy.com',
replyTo: 'yyyy@yyyy.com',
subject: 'project build failed',
to: 'zzzz@yyyyy.com'*/
throw err
}
}