node('node') {
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 Docker'
sh './dockerBuild.sh'
stage 'Deploy'
echo 'Push to Repo'
sh './dockerPushToRepo.sh'
echo 'ssh to web server and tell it to pull new image'
sh 'ssh [email protected] running/xxxxxxx/dockerRun.sh'
stage 'Cleanup'
echo 'prune and cleanup'
sh 'npm prune'
sh 'rm node_modules -rf'
mail body: 'project build successful',
from: '[email protected]',
replyTo: '[email protected]',
subject: 'project build successful',
to: '[email protected]'
}
catch (err) {
currentBuild.result = "FAILURE"
mail body: "project build error: ${err}" ,
from: '[email protected]',
replyTo: '[email protected]',
subject: 'project build failed',
to: '[email protected]'
throw err
}
}