-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
58 lines (55 loc) · 2.19 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Running build automation babs_oxi_polymerase container'
}
}
stage('Build Docker Image') {
when {
branch 'main'
}
steps {
script {
app = docker.build("thefranciscrickinstitute/babs_oxi_polymerase-image")
app.inside {
sh 'echo Hello test container'
}
}
}
}
stage('Push Docker Image') {
when {
branch 'main'
}
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
}
stage('Deploy To Staging Environment') {
when {
branch 'main'
}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerdeploy', usernameVariable: 'USERNAME', passwordVariable: 'USERPASS')]) {
script {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$dockerip \"docker pull thefranciscrickinstitute/babs_oxi_polymerase-image:${env.BUILD_NUMBER}\""
try {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$dockerip \"docker stop babs_oxi_polymerase\""
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$dockerip \"docker rm babs_oxi_polymerase\""
} catch (err) {
echo: 'caught error: $err'
}
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$dockerip \"docker run --restart always --name babs_oxi_polymerase -p 80:8080 -d thefranciscrickinstitute/babs_oxi_polymerase-image:${env.BUILD_NUMBER}\""
}
}
}
}
}
}