Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #37

Open
wants to merge 54 commits into
base: qa
Choose a base branch
from
Open

Dev #37

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
12a7824
Update README.md
ravdy Aug 16, 2022
ca58efc
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
8eafe4c
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
9554a76
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
f76018e
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
8479f15
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
a88753f
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
d1ef82f
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
e0b93f1
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
22c5047
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
3349117
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
7c01013
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
523c8a7
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
7630e9b
Update README.md
ashirwad8858 Feb 21, 2024
a05dde6
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
5790b77
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
1200872
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
c772f44
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
98f08dd
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
f44467b
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
094c34d
Merge pull request #1 from ashirwad8858/qa
ashirwad8858 Feb 21, 2024
8996b82
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
ccc9635
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
ef9ea5d
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
b38c802
Update Jenkinsfile
ashirwad8858 Feb 21, 2024
f2c1be0
Create deploy.sh
ashirwad8858 Feb 21, 2024
4724707
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
d4bdba6
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
e0970db
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
dec2aef
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
4dcfb6c
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
6ac6cc9
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
f1f62d1
Update Jenkinsfile
ashirwad8858 Feb 22, 2024
13d157c
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
1415fdf
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
8b71566
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
1960a45
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
5a20371
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
7b7815a
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
2030491
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
a831c51
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
46ec7b8
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
0e03c89
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
d1b89a5
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
bbf8661
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
09c5ab9
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
47d34d2
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
a30cfcf
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
dd489af
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
0f7d157
Create dunkins-jenkinsfile
ashirwad8858 Feb 23, 2024
0f9da57
Create Dockerfile
ashirwad8858 Feb 23, 2024
1ab5bdc
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
d69a006
Update Jenkinsfile
ashirwad8858 Feb 23, 2024
27098c7
Create 300moves-jenkinsfile
ashirwad8858 Feb 27, 2024
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
92 changes: 92 additions & 0 deletions 300moves-jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
pipeline {
agent any
environment {
ENV = credentials("300Moves_${env.BRANCH_NAME}_env")
Server_ip = credentials("300Moves_${env.BRANCH_NAME}_server_ip")
CREDENTIALS = credentials("gitlab-token")
}
stages{
stage("cleanup"){
steps {
deleteDir()
}
}
stage ('Git clone'){
steps{
checkout scm
}

}
stage('SonarQube Analysis') {
when {
branch 'dev'
}
steps {
script {
scannerHome = tool 'Zapbuildsonarqube'
}
withSonarQubeEnv('sonar-global') {
sh "${scannerHome}/bin/sonar-scanner \
-D sonar.token=${SONAR_TOKEN} \
-D sonar.projectKey=300moves-dev \
-D sonar.sources=. \
-D sonar.host.url=http://sonarqube.zapbuild.in:9000/"
}
}
post {
always {
script {
def sonarqubeUrl = env.getProperty('sonarqube_url_id')

emailext subject: '[${JOB_NAME}] - Sonarqube Scanning',
body: "Sonarqube scanning has been completed successfully. Click [here](${sonarqubeUrl}=300moves-dev) to check status",
to: '[email protected]',
replyTo: '[email protected]',
from: "[email protected]"
}
}
}
}



stage ("Build"){
when {
not {
branch 'master'
}
}
steps {
sh 'echo "300Moves_${BRANCH_NAME}_env"'
sh 'cp $ENV .'
sh 'zip -r website.zip .'
}
}
stage ("Deploy on DevServer"){
steps{
script{
if (env.BRANCH_NAME == 'dev'){
sh 'echo "dev server"'
sh 'scp website.zip deploy.sh jenkins@$Server_ip:/var/www/html/jenkindeploy/300moves/${BRANCH_NAME}'
sh 'ssh jenkins@$Server_ip "cd /var/www/html/jenkindeploy/300moves/${BRANCH_NAME} && chmod 755 deploy.sh && sh deploy.sh"'
} else if (env.BRANCH_NAME == 'qa') {
// Deploy to qa server
sh 'echo "qa deployment"'
sh 'scp website.zip deploy.sh jenkins@$Server_ip:/var/www/html/jenkindeploy/300moves/${BRANCH_NAME}'
sh 'ssh jenkins@$Server_ip "cd /var/www/html/jenkindeploy/300moves/${BRANCH_NAME} && chmod 755 deploy.sh && sh deploy.sh"'
} else if (env.BRANCH_NAME == 'master') {
// Deploy to stage server
sh 'echo "Live deploymebnt"'
sh 'ssh ubuntu@$Server_ip "cd /var/www/html/300moves/public_html/ && git pull https://${CREDENTIALS_USR}:${CREDENTIALS_PSW}@gitlab.zapbuild.com/zapbuild/cwvr.git master"'
sh 'scp ${ENV} ubuntu@$Server_ip:/var/www/html/300moves/public_html/'
sh 'ssh ubuntu@$Server_ip "cd /var/www/html/300moves/public_html/ && docker-compose up --build -d"'
}
}
//sh 'echo "Deployment"'
//sh 'scp website.zip deploy.sh jenkins@$Server_ip:/var/www/html/jenkindeploy/300moves/${BRANCH_NAME}'
//sh 'ssh jenkins@$Server_ip "cd /var/www/html/jenkindeploy/300moves/${BRANCH_NAME} && chmod 755 deploy.sh && sh deploy.sh"'
}
}
}

}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as the base image
FROM node:14

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json (if available) to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code to the working directory
COPY . .

# Expose the port the app runs on
EXPOSE 3000

# Command to run the application
CMD ["node", "server.js"]
98 changes: 93 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,116 @@
def VAR = null
pipeline {

agent any
environment{
DEV_ENV = 'devserver_ip'
// VAR = null
}
// options {
// skipDefaultCheckout(true)
// }

stages {
stage('Set Environment') {
steps {
script {
def branchName = env.BRANCH_NAME
sh "echo '${env.BRANCH_NAME}'"
if (branchName == 'dev') {
sh "echo 'DEV==>'"
VAR = 'development'
echo "var======> ${VAR}"
//ENV = credentials('DEV_ENV')
} else if (branchName == 'qa') {
sh "echo 'QA==>'"
VAR = 'quality analyst'
//ENV = credentials('QA_ENV')
echo "var======> ${VAR}"
} else {
error "Branch not supported"
}
}
}
}

stage('Install Dependencies') {
steps {
sh 'npm install'
sh 'echo "Install Dependencies ${VAR} ==>> ${DEV_ENV} ${GIT_URL}"'
script{
echo "Current branch: ${VAR} Dunkins_${env.BRANCH_NAME}_env"
echo "Git repo: ${env.GIT_URL}"
}
}
}
stage('Checkout') {
steps {
// Automatically checks out the source code for the branch that triggered the build
checkout scm
}
}

// stage('Git Clone') {
// steps {
// // Git clone step
// script{
// // git branch: "${env.BRANCH_NAME}", credentialsId: 'git-hub', URL: "${env.GIT_URL}"
// git branch: "${env.BRANCH_NAME}", credentialsId: 'git-hub', URL: 'https://github.com/ashirwad8858/test-nodejs-app-jenkins-pipline.git'

// }
// }
// }

stage('Test') {
stage('Test DEV') {
when {
branch 'dev'
}
steps {
sh 'echo "testing application..."'
}
}
stage('Test QA') {
when {
branch 'qa'
}
steps {
sh 'echo "testing application..."'
}
}
stage('Docker Build') {
steps {
// Docker build step
script {
app = docker.build("myapp:1")
}
}
}

stage("Deploy application") {
steps {
sh 'echo "deploying application..."'
}
steps {
// Deploy step
script {
if (env.BRANCH_NAME == 'dev') {
// Deploy to dev server
sh 'echo "dev deploymebnt"'
} else if (env.BRANCH_NAME == 'qa') {
// Deploy to qa server
sh 'echo "qa deploymebnt"'
} else if (env.BRANCH_NAME == 'stage') {
// Deploy to stage server
sh 'echo "stage deploymebnt"'
}
}
}

}

}








}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build and Deploy nodejs application on EC2 instance - Freestyle
# QA Build and Deploy nodejs application on EC2 instance - Freestyle

# Pre-requisites

Expand Down Expand Up @@ -28,7 +28,6 @@ Github URL: https://github.com/ravdy/nodejs.git

Using simple "hello world" application from the [nodejs.org](https://nodejs.org/en/docs/guides/getting-started-guide/) website


## On Jenkins GUI

1. Create the new FreeStyle Project
Expand Down
1 change: 1 addition & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

67 changes: 67 additions & 0 deletions dunkins-jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
pipeline {
agent any
environment {
ENV = credentials("300Moves_${env.BRANCH_NAME}_env")
Server_ip = credentials("300Moves_${env.BRANCH_NAME}_server_ip")
}
stages{
stage("cleanup"){
steps {
deleteDir()
}
}
stage ('Git clone'){
steps{
checkout scm
}

}
stage('SonarQube Analysis') {
when {
branch 'dev'
}
steps {
script {
scannerHome = tool 'Zapbuildsonarqube'
}
withSonarQubeEnv('sonar-global') {
sh "${scannerHome}/bin/sonar-scanner \
-D sonar.token=${SONAR_TOKEN} \
-D sonar.projectKey=300moves-dev \
-D sonar.sources=. \
-D sonar.host.url=http://sonarqube.zapbuild.in:9000/"
}
}
post {
always {
script {
def sonarqubeUrl = env.getProperty('sonarqube_url_id')

emailext subject: '[${JOB_NAME}] - Sonarqube Scanning',
body: "Sonarqube scanning has been completed successfully. Click [here](${sonarqubeUrl}=300moves-dev) to check status",
to: '[email protected]',
replyTo: '[email protected]',
from: "[email protected]"
}
}
}
}



stage ("Build"){
steps {
sh 'cp $ENV .'
sh 'zip -r website.zip .'
}
}
stage ("Deploy on DevServer"){
steps{
sh 'echo "Deployment"'
// sh 'scp website.zip deploy.sh jenkins@$Server_ip:/var/www/jenkindeploy/300moves/$ENV'
// sh 'ssh jenkins@$Server_ip "cd /var/www/jenkindeploy/300moves/$ENV && chmod 755 deploy.sh && sh deploy.sh"'
}
}
}

}