Merge pull request 'Add Jenkins CI pipeline and automated Node.js tests' (#8) from feature/jenkins-ci into main
Reviewed-on: #8 Reviewed-by: shiv <Shivpatel2002@gmail.com>
This commit was merged in pull request #8.
This commit is contained in:
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
timeout(time: 5, unit: 'MINUTES')
|
||||
buildDiscarder(logRotator(numToKeepStr: '5'))
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Verify Node.js') {
|
||||
steps {
|
||||
sh 'node --version'
|
||||
sh 'npm --version'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Syntax Check') {
|
||||
steps {
|
||||
dir('app') {
|
||||
sh 'npm run check'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Automated Tests') {
|
||||
steps {
|
||||
dir('app') {
|
||||
sh 'npm test'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo 'CI PASSED: All checks completed successfully.'
|
||||
}
|
||||
failure {
|
||||
echo 'CI FAILED: Review the Jenkins console output.'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "startup-product",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "node --test",
|
||||
"check": "node --check src/health.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
function getHealthStatus(databaseConnected) {
|
||||
return {
|
||||
status: databaseConnected ? "healthy" : "unhealthy",
|
||||
database: databaseConnected ? "connected" : "disconnected"
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { getHealthStatus };
|
||||
@@ -0,0 +1,17 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { getHealthStatus } = require("../src/health");
|
||||
|
||||
test("reports healthy when database is connected", () => {
|
||||
assert.deepEqual(getHealthStatus(true), {
|
||||
status: "healthy",
|
||||
database: "connected"
|
||||
});
|
||||
});
|
||||
|
||||
test("reports unhealthy when database is disconnected", () => {
|
||||
assert.deepEqual(getHealthStatus(false), {
|
||||
status: "unhealthy",
|
||||
database: "disconnected"
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
Jenkins webhook automatic build test
|
||||
Reference in New Issue
Block a user