-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
38 lines (38 loc) · 1.45 KB
/
Jenkinsfile
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
pipeline {
agent any
stages {
stage("checkout") {
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'github', url: 'https://github.com/mihirh19/docker_jenkins_pipeline']])
}
}
stage("Build Image") {
steps {
script {
if (isUnix()) {
sh 'docker build -t mihir2109/dockerpipeline .'
} else {
bat 'docker build -t mihir2109/dockerpipeline .'
}
}
}
}
stage('Docker Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'DOCKERHUB_PASSWORD', usernameVariable: 'DOCKERHUB_USERNAME')]) {
script {
if (isUnix()) {
sh 'docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD'
sh 'docker push mihir2109/dockerpipeline'
sh 'docker logout'
} else {
bat 'docker login -u %DOCKERHUB_USERNAME% -p %DOCKERHUB_PASSWORD%'
bat 'docker push mihir2109/dockerpipeline'
bat 'docker logout'
}
}
}
}
}
}
}