-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create JenkinsPiplelineScriptDockerSwarm_Private_Repo
- Loading branch information
1 parent
0f15cc9
commit 631cc75
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
node{ | ||
|
||
def buildNumber = BUILD_NUMBER | ||
|
||
stage("Git CheckOut"){ | ||
git url: 'https://github.com/MithunTechnologiesDevOps/java-web-app-docker.git',branch: 'master' | ||
} | ||
|
||
stage(" Maven Clean Package"){ | ||
def mavenHome = tool name: "Maven-3.6.2", type: "maven" | ||
def mavenCMD = "${mavenHome}/bin/mvn" | ||
sh "${mavenCMD} clean package" | ||
} | ||
|
||
stage("Build Dokcer Image") { | ||
sh "docker build -t 172.31.1.204:8083/java-web-app:${buildNumber} ." | ||
} | ||
|
||
|
||
stage("Docker Push"){ | ||
|
||
withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) { | ||
sh "docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083" | ||
} | ||
|
||
sh "docker push 172.31.1.204:8083/java-web-app:${buildNumber}" | ||
} | ||
|
||
stage("Deploy to docker swarm cluster"){ | ||
sshagent(['Docker_Swarm_Manager_Dev']) { | ||
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker service rm javawebapp || true' | ||
withCredentials([string(credentialsId: 'Docker_Repo_Pwd', variable: 'Docker_Repo_Pwd')]) { | ||
|
||
sh "ssh -o StrictHostKeyChecking=no [email protected] docker login -u admin -p ${Docker_Repo_Pwd} 172.31.1.204:8083" | ||
} | ||
sh "ssh [email protected] docker service create --name javawebapp -p 7070:8080 --replicas 2 --with-registry-auth 172.31.1.204:8083/java-web-app:${buildNumber}" | ||
} | ||
} | ||
|
||
} |