Fixed Jenkinsfile
This commit is contained in:
80
Jenkinsfile
vendored
80
Jenkinsfile
vendored
@@ -1,32 +1,18 @@
|
|||||||
#!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 {
|
node {
|
||||||
|
stage('Checkout') {
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Prepare') {
|
||||||
sh 'git rev-parse --verify HEAD > GIT_COMMIT'
|
sh 'git rev-parse --verify HEAD > GIT_COMMIT'
|
||||||
env.GIT_COMMIT = readFile('GIT_COMMIT').trim().substring(0, 10)
|
env.GIT_COMMIT = readFile('GIT_COMMIT').trim().substring(0, 10)
|
||||||
sh 'rm GIT_COMMIT'
|
sh 'rm GIT_COMMIT'
|
||||||
def jobName = env.JOB_NAME.tokenize('/')
|
def jobName = env.JOB_NAME.tokenize('/')
|
||||||
print env.jobName
|
print env.jobName
|
||||||
|
|
||||||
|
// set env
|
||||||
env.DOCKER_NAME="${jobName[0]}/${jobName[1]}:${env.BRANCH_NAME}-${env.GIT_COMMIT}"
|
env.DOCKER_NAME="${jobName[0]}/${jobName[1]}:${env.BRANCH_NAME}-${env.GIT_COMMIT}"
|
||||||
env.DOCKER_REGISTRY="docker.sebse.de"
|
env.DOCKER_REGISTRY="docker.sebse.de"
|
||||||
|
|
||||||
@@ -34,93 +20,47 @@ node {
|
|||||||
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
|
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
|
||||||
|
|
||||||
def customImage
|
def customImage
|
||||||
|
|
||||||
|
|
||||||
currentBuild.result = "SUCCESS"
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
stage('Checkout'){
|
|
||||||
|
|
||||||
checkout scm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Test'){
|
/*stage('Test') {
|
||||||
|
|
||||||
env.NODE_ENV = "test"
|
env.NODE_ENV = "test"
|
||||||
|
|
||||||
print "Environment will be : ${env.NODE_ENV}"
|
print "Environment will be : ${env.NODE_ENV}"
|
||||||
|
|
||||||
sh 'node -v'
|
sh 'node -v'
|
||||||
sh 'npm prune'
|
sh 'npm prune'
|
||||||
sh 'npm install'
|
sh 'npm install'
|
||||||
//sh 'npm test'
|
sh 'npm test'
|
||||||
|
}*/
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build Prod') {
|
stage('Build Prod') {
|
||||||
|
|
||||||
env.NODE_ENV = "production"
|
env.NODE_ENV = "production"
|
||||||
|
|
||||||
print "Environment will be : ${env.NODE_ENV}"
|
print "Environment will be : ${env.NODE_ENV}"
|
||||||
|
|
||||||
sh 'node -v'
|
sh 'node -v'
|
||||||
sh 'npm prune'
|
sh 'npm prune'
|
||||||
sh 'npm install --production=false'
|
sh 'npm install --production=false'
|
||||||
sh './node_modules/.bin/tsc'
|
sh 'npm run build'
|
||||||
sh 'rm node_modules -rf'
|
sh 'rm node_modules -rf'
|
||||||
sh 'npm install --only=production'
|
sh 'npm install --only=production'
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Docker') {
|
stage('Build Docker') {
|
||||||
|
|
||||||
customImage = docker.build(env.DOCKER_NAME)
|
customImage = docker.build(env.DOCKER_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
|
|
||||||
echo 'Push to Repo'
|
echo 'Push to Repo'
|
||||||
docker.withRegistry("https://${DOCKER_REGISTRY}", 'docker-registry-robot-web-development') {
|
docker.withRegistry("https://${DOCKER_REGISTRY}", 'docker-registry-robot-web-development') {
|
||||||
|
|
||||||
/* Push the container to the custom Registry */
|
/* Push the container to the custom Registry */
|
||||||
customImage.push()
|
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') {
|
stage('Cleanup') {
|
||||||
|
|
||||||
echo 'prune and cleanup'
|
echo 'prune and cleanup'
|
||||||
sh 'npm prune'
|
sh 'npm prune'
|
||||||
sh 'rm node_modules -rf'
|
sh 'rm node_modules -rf'
|
||||||
sh "docker rmi ${env.DOCKER_NAME} ${DOCKER_REGISTRY}/${env.DOCKER_NAME}"
|
sh "docker rmi ${env.DOCKER_NAME} ${DOCKER_REGISTRY}/${env.DOCKER_NAME}"
|
||||||
sh 'docker image prune -f'
|
sh 'docker image prune -f'
|
||||||
sh 'docker rmi $(docker images -a | grep "<none>" | awk "{print \$3}") &2>/del/null || exit 0'
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
package.json
15
package.json
@@ -4,13 +4,19 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
|
||||||
"start": "node ./dist/index.js",
|
"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": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
|
"pug": "^3.0.2"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.11",
|
"@types/express": "^4.17.11",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^14.14.41",
|
||||||
@@ -18,10 +24,5 @@
|
|||||||
"@types/pug": "^2.0.4",
|
"@types/pug": "^2.0.4",
|
||||||
"tsc-watch": "^4.2.9",
|
"tsc-watch": "^4.2.9",
|
||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"express": "^4.17.1",
|
|
||||||
"node-fetch": "^2.6.1",
|
|
||||||
"pug": "^3.0.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user