add test-cicd code
This commit is contained in:
67
code/sample-nodejs-app/Jenkinsfile
vendored
Normal file
67
code/sample-nodejs-app/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
APP_NAME = 'sample-nodejs-app'
|
||||
DOCKER_IMAGE = "test-cicd/${APP_NAME}:${env.BUILD_NUMBER}"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install Dependencies') {
|
||||
steps {
|
||||
dir('code/sample-nodejs-app') {
|
||||
sh 'npm install'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Test') {
|
||||
steps {
|
||||
dir('code/sample-nodejs-app') {
|
||||
sh 'npm test'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Docker Image') {
|
||||
steps {
|
||||
dir('code/sample-nodejs-app') {
|
||||
sh "docker build -t ${APP_NAME}:latest ."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push to Registry') {
|
||||
steps {
|
||||
echo 'Pushing image to registry...'
|
||||
// sh "docker tag ${APP_NAME}:latest ${DOCKER_IMAGE}"
|
||||
// sh "docker push ${DOCKER_IMAGE}"
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy to K8s') {
|
||||
steps {
|
||||
echo 'Deploying to Kubernetes...'
|
||||
// sh "kubectl set image deployment/${APP_NAME} ${APP_NAME}=${DOCKER_IMAGE}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
cleanWs()
|
||||
}
|
||||
success {
|
||||
echo 'Pipeline completed successfully!'
|
||||
}
|
||||
failure {
|
||||
echo 'Pipeline failed!'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user