simple jenkinsfile
This commit is contained in:
58
Jenkinsfile
vendored
Normal file
58
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
// Replace with your actual registry URL (e.g., harbor.example.com or docker.io)
|
||||
REGISTRY_URL = 'localhost:5000'
|
||||
IMAGE_NAME = 'hello-world-node'
|
||||
// The ID of the credentials you've stored in Jenkins for your registry
|
||||
REGISTRY_CREDENTIALS_ID = 'registry-credentials'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
// This stage is usually handled automatically by Jenkins when using a Multibranch Pipeline or SCM
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
echo "Building image: ${REGISTRY_URL}/${IMAGE_NAME}:${env.BUILD_NUMBER}"
|
||||
// Build the image using the multistage Dockerfile
|
||||
dockerImage = docker.build("${REGISTRY_URL}/${IMAGE_NAME}:${env.BUILD_NUMBER}", "./hello-world-node")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push to Registry') {
|
||||
steps {
|
||||
script {
|
||||
// Log in to the registry using stored credentials and push the image
|
||||
docker.withRegistry("http://${REGISTRY_URL}", REGISTRY_CREDENTIALS_ID) {
|
||||
dockerImage.push()
|
||||
dockerImage.push('latest')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Cleanup') {
|
||||
steps {
|
||||
sh "docker rmi ${REGISTRY_URL}/${IMAGE_NAME}:${env.BUILD_NUMBER}"
|
||||
sh "docker rmi ${REGISTRY_URL}/${IMAGE_NAME}:latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo 'Deployment successful!'
|
||||
}
|
||||
failure {
|
||||
echo 'Deployment failed. Check the logs for details.'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user