-
Notifications
You must be signed in to change notification settings - Fork 239
/
Jenkinsfile
57 lines (57 loc) · 1.42 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
#!/usr/bin/env groovy
def appName = 'shipitclicker'
def dockerfile = 'chapter7/Dockerfile'
def registry = 'https://registry-1.docker.io/'
def getImageName(appName) {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'shipit.dockerhub.id',
usernameVariable: 'dh_user',
passwordVariable: 'dh_password']]) {
"${dh_user}/${appName}:${env.BUILD_ID}"
}
}
def getTarget() {
env.BRANCH_NAME == 'staging' ? 'staging' : 'prod'
}
pipeline {
agent any
stages {
stage('build') {
steps {
checkout scm
script {
docker.withRegistry(registry, 'shipit.dockerhub.id') {
def image = docker.build(
getImageName(appName),
"-f ${dockerfile} --network host ./chapter7"
)
image.push()
}
}
}
}
stage('deploy') {
when {
anyOf {
branch 'master'
branch 'staging'
}
}
steps {
echo "BRANCH_NAME is ${env.BRANCH_NAME}"
echo "Deploying to ${getTarget()}"
withCredentials([sshUserPrivateKey(
credentialsId: 'jenkins.shipit',
keyFileVariable: 'keyfile')]) {
sh """
set -a
target=${getTarget()}
image=${getImageName(appName)}
keyfile=${keyfile}
./chapter7/bin/ssh-dep.sh
"""
}
}
}
}
}