Skip to content
Open
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
49 changes: 49 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pipeline {
agent {
// Use Node 16 Docker image as the build agent
docker { image 'node:16' }
}

environment {
// Set the Docker image name and tag
IMAGE_NAME = 'chiamintwts/assignment2_22165266:latest'
}

stages {
stage('Install Dependencies') {
steps {
// Install dependencies - Node.js
sh 'npm install'
}
}
stage('Run Unit Tests') {
steps {
// Run the test suite
sh 'npm test'
}
}
stage('Security Scan') {
steps {
// Install Snyk CLI and run a scan
sh 'npm install -g snyk'
// Pipeline fails if any high severity issues are found
sh 'snyk test --severity-threshold=high'
}
}
stage('Build Docker Image') {
steps {
// Build the Docker image for the app
sh 'docker build -t $IMAGE_NAME .'
}
}
stage('Push Docker Image') {
steps {
// Login to Docker Hub and push the image
withCredentials([usernamePassword(credentialsId: 'dockerhub-credentials', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) {
sh 'echo $DOCKERHUB_PASS | docker login -u $DOCKERHUB_USER --password-stdin'
sh 'docker push $IMAGE_NAME'
}
}
}
}
}