diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..6c0219b --- /dev/null +++ b/Jenkinsfile @@ -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.' + } + } +} diff --git a/app/package.json b/app/package.json new file mode 100644 index 0000000..bdedf8b --- /dev/null +++ b/app/package.json @@ -0,0 +1,9 @@ +{ + "name": "startup-product", + "version": "1.0.0", + "private": true, + "scripts": { + "test": "node --test", + "check": "node --check src/health.js" + } +} diff --git a/app/src/health.js b/app/src/health.js new file mode 100644 index 0000000..b716c60 --- /dev/null +++ b/app/src/health.js @@ -0,0 +1,8 @@ +function getHealthStatus(databaseConnected) { + return { + status: databaseConnected ? "healthy" : "unhealthy", + database: databaseConnected ? "connected" : "disconnected" + }; +} + +module.exports = { getHealthStatus }; diff --git a/app/test/health.test.js b/app/test/health.test.js new file mode 100644 index 0000000..2757eef --- /dev/null +++ b/app/test/health.test.js @@ -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" + }); +}); diff --git a/ci-webhook-test.txt b/ci-webhook-test.txt new file mode 100644 index 0000000..283299c --- /dev/null +++ b/ci-webhook-test.txt @@ -0,0 +1 @@ +Jenkins webhook automatic build test