add test-cicd code

This commit is contained in:
2026-04-17 09:15:51 +07:00
parent 11bb25d772
commit 26ac517674
5 changed files with 142 additions and 0 deletions

67
code/sample-nodejs-app/Jenkinsfile vendored Normal file
View 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!'
}
}
}