-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
58 lines (51 loc) · 1.79 KB
/
Copy pathJenkinsfile
File metadata and controls
58 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pipeline {
agent any // Ensure the agent has Docker installed
environment {
DOCKER_HUB_REPO = 'emma2323/bank-cicd-site' // Updated to your Docker Hub username
DOCKER_TAG = 'latest' // Or use "${env.BUILD_NUMBER}" for versioning
DOCKER_IMAGE = "${DOCKER_HUB_REPO}:${DOCKER_TAG}"
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Cloud-Architect-Emma/bank-cicd-site.git'
}
}
stage('Build') {
steps {
echo 'Building project...'
sh 'echo Build successful!' // Replace with actual build commands if needed (e.g., npm install, mvn build)
}
}
stage('Docker Build & Push') {
steps {
script {
// Build the Docker image
dockerImage = docker.build(DOCKER_IMAGE)
// Login to Docker Hub and push using credentials
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-creds') {
dockerImage.push()
}
}
}
}
stage('Deploy') {
steps {
echo 'Deploying application...'
sh 'echo Deployment successful!' // Update with real deploy commands (e.g., kubectl apply -f deployment.yaml)
}
}
}
post {
always {
// Clean up local Docker images to free space
sh "docker rmi ${DOCKER_IMAGE} || true"
}
success {
echo 'Pipeline completed successfully! Image pushed to Docker Hub.'
}
failure {
echo 'Pipeline failed. Check logs for details.'
}
}
}