Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
readme
7 changes: 4 additions & 3 deletions _config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ var config = {}

// Update to have your correct username and password
config.mongoURI = {
production: 'mongodb+srv://<USERNAME>:<PASSWORD>@gallery.wc344.mongodb.net/darkroom?retryWrites=true&w=majority',
development: 'mongodb+srv://<USERNAME>:<PASSWORD>@gallery.wc344.mongodb.net/darkroom-dev?retryWrites=true&w=majority',
test: 'mongodb+srv://<USERNAME>:<PASSWORD>@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;
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is in deployment
12 changes: 5 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions views/index.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
Expand All @@ -12,7 +12,7 @@
<div class="navbar-fixed">
<nav class="turquoise" >
<div class="nav-wrapper container">
<a href="/" class="brand-logo ">Darkroom</a>
<a href="/" class="brand-logo ">Darkroom Gibson_IP1</a>
<form class="right">
<div class="input-field ">
<input id="search" class="left" type="search" required>
Expand All @@ -29,6 +29,9 @@
</div>

<div class="container">
<h1>MILESTONE 2</h1>
<h1>MILESTONE 3</h1>
<h1>MILESTONE 4</h1>
<h1>Image Upload </h1>
<%= typeof msg != 'undefined' ? msg : '' %>
<form action="/upload" method = "POST" enctype="multipart/form-data">
Expand Down Expand Up @@ -67,4 +70,4 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>