diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..e08636444 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,123 @@ +pipeline { + agent any + + environment { + SLACK_CHANNEL = '#gibson_ip1' + SLACK_CREDENTIALS_ID = 'slack-token' + GIT_REPO = 'https://github.com/Gibwanjau/gallery.git' + GIT_BRANCH = 'main' + GIT_CREDENTIALS_ID = 'git-token' + EMAIL_RECIPIENT = 'gibson.wanjau1@student.moringaschool.com' + + stages { + stage('Checkout') { + steps { + script { + // Checkout the code from the repository + checkout([$class: 'GitSCM', branches: [[name: "*/${GIT_BRANCH}"]], + userRemoteConfigs: [[url: GIT_REPO, credentialsId: GIT_CREDENTIALS_ID]]]) + } + } + } + + stage('Install Node and Dependencies') { + steps { + script { + // Install Node.js and npm (if not installed) + sh 'curl -sL https://deb.nodesource.com/setup_14.x | bash -' + sh 'apt-get install -y nodejs' + + // Install npm dependencies + sh 'npm install' + } + } + } + + stage('Build') { + steps { + script { + // Build the application + sh 'npm run build' + } + } + } + + stage('Test') { + steps { + script { + // Run tests + sh 'npm test' + } + } + } + + stage('Deploy') { + steps { + script { + // Deploy the application (this is a placeholder; replace with actual deployment commands) + echo 'Deploying the application...' + } + } + } + + stage('Git Push') { + steps { + script { + // Configure Git user + sh ''' + git config user.name "Your Name" + git config user.email "youremail@example.com" + ''' + + // Add changes + sh 'git add .' + + // Commit changes + sh 'git commit -m "Automated commit from Jenkins build #${env.BUILD_NUMBER}" || echo "No changes to commit"' + + // Push changes + sh 'git push origin ${GIT_BRANCH}' + } + } + } + + stage('Notify') { + steps { + script { + slackSend(channel: SLACK_CHANNEL, + message: "Build #${env.BUILD_NUMBER} completed: ${currentBuild.currentResult}", + tokenCredentialId: SLACK_CREDENTIALS_ID) + } + } + } + } + + post { + always { + script { + slackSend(channel: SLACK_CHANNEL, + message: "Build #${env.BUILD_NUMBER} finished with status: ${currentBuild.currentResult}", + tokenCredentialId: SLACK_CREDENTIALS_ID) + } + } + success { + script { + slackSend(channel: SLACK_CHANNEL, + message: "Build #${env.BUILD_NUMBER} succeeded!", + tokenCredentialId: SLACK_CREDENTIALS_ID) + } + } + failure { + script { + // Send email notification on failure + mail to: EMAIL_RECIPIENT, + subject: "Build #${env.BUILD_NUMBER} Failed", + body: "The build failed. Check Jenkins for more details." + + slackSend(channel: SLACK_CHANNEL, + message: "Build #${env.BUILD_NUMBER} failed!", + tokenCredentialId: SLACK_CREDENTIALS_ID) + } + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 000000000..8178c76d6 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +readme diff --git a/_config.js b/_config.js index 23720eb7c..65721d3e5 100644 --- a/_config.js +++ b/_config.js @@ -2,8 +2,9 @@ var config = {} // Update to have your correct username and password config.mongoURI = { - production: 'mongodb+srv://:@gallery.wc344.mongodb.net/darkroom?retryWrites=true&w=majority', - development: 'mongodb+srv://:@gallery.wc344.mongodb.net/darkroom-dev?retryWrites=true&w=majority', - test: 'mongodb+srv://:@gallery.wc344.mongodb.net/darkroom-test?retryWrites=true&w=majority', + production: 'mongodb+srv://gallery:Gallery12345@cluster0.dxryi.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0', + development: 'mongodb+srv://gallery:Gallery12345@cluster0.dxryi.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0', + test: 'mongodb+srv://gallery:Gallery12345@cluster0.dxryi.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0', + } module.exports = config; diff --git a/readme.txt b/readme.txt new file mode 100644 index 000000000..e4791a5e3 --- /dev/null +++ b/readme.txt @@ -0,0 +1 @@ +This is in deployment diff --git a/server.js b/server.js index 0d6265601..cd1dbbb3d 100644 --- a/server.js +++ b/server.js @@ -13,13 +13,11 @@ const app = express(); // connecting the database -const MONGODB_URI = process.env.MONGODB_URI || config.mongoURI[app.settings.env] -mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true },(err)=>{ - if (err) { - console.log(err) - }else{ - console.log(`Connected to Database: ${MONGODB_URI}`) - } +let mongodb_url = 'mongodb+srv://gallery:Gallery12345@cluster0.dxryi.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'; +let dbName = 'galleryGibson_ip1'; +mongoose.connect(`${mongodb_url}${dbName}`,{ useNewUrlParser: true , useUnifiedTopology: true }, (err)=>{ + if (err) console.log(err) + }); // test if the database has connected successfully diff --git a/views/index.ejs b/views/index.ejs index c5b1c5693..ce5dfb37c 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,6 +1,6 @@ - + @@ -12,7 +12,7 @@