Skip to content

Commit e2f480d

Browse files
committed
Add Jenkinsfile for CI/CD pipeline
1 parent 752349c commit e2f480d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Jenkinsfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
IMAGE_NAME = "your-dockerhub-username/java-web-calculator"
6+
}
7+
8+
stages {
9+
stage('Clone Repo') {
10+
steps {
11+
echo 'Code already cloned by Jenkins.'
12+
}
13+
}
14+
15+
stage('Build Docker Image') {
16+
steps {
17+
script {
18+
sh 'docker build -t $IMAGE_NAME .'
19+
}
20+
}
21+
}
22+
23+
stage('Login to Docker Hub') {
24+
steps {
25+
withCredentials([usernamePassword(credentialsId: 'docker-hub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
26+
sh 'echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin'
27+
}
28+
}
29+
}
30+
31+
stage('Push to Docker Hub') {
32+
steps {
33+
sh 'docker push $IMAGE_NAME'
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)