From 143af212f0a63498c04d948cc48b9b9016beb1af Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Wed, 26 Jan 2022 00:14:02 +0100 Subject: [PATCH] Fixed Jenkinsfile --- Jenkinsfile | 180 +++++++++++++++++---------------------------------- package.json | 15 +++-- 2 files changed, 68 insertions(+), 127 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3c4188a..65d70ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,126 +1,66 @@ #!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 "" | 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 + stage('Checkout') { + checkout scm } + stage('Prepare') { + 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 + + // set env + 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 + } + + /*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 'npm run build' + 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() + } + } + + 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 "" | awk "{print \$3}") &2>/del/null || exit 0' + } } diff --git a/package.json b/package.json index eb76790..9f61cda 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,19 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", "start": "node ./dist/index.js", - "dev": "tsc-watch --onSuccess \"node ./dist/index.js\"" + "dev": "tsc-watch --onSuccess \"node ./dist/index.js\" --onFailure \"echo Beep! Compilation Failed\"", + "build": "tsc", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", + "dependencies": { + "express": "^4.17.1", + "node-fetch": "^2.6.1", + "pug": "^3.0.2" + }, "devDependencies": { "@types/express": "^4.17.11", "@types/node": "^14.14.41", @@ -18,10 +24,5 @@ "@types/pug": "^2.0.4", "tsc-watch": "^4.2.9", "typescript": "^4.2.4" - }, - "dependencies": { - "express": "^4.17.1", - "node-fetch": "^2.6.1", - "pug": "^3.0.2" } }