-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
60 lines (53 loc) · 2.61 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
59
60
#!/usr/bin/env groovy
pipeline {
agent any
environment {
TAG_NAME = sh(returnStdout: true, script: '[[ -z $(git tag -l --points-at HEAD) ]] && printf latest || printf $(git tag -l --points-at HEAD)')
LOCAL_IMAGE_NAME = "geoimagenet_graphql:$TAG_NAME"
LATEST_IMAGE_NAME = "docker-registry.crim.ca/geoimagenet/graphql:latest"
TAGGED_IMAGE_NAME = "docker-registry.crim.ca/geoimagenet/graphql:$TAG_NAME"
}
options {
buildDiscarder (logRotator(numToKeepStr:'10'))
}
stages {
stage('Build') {
steps {
sh 'env | sort'
sh 'docker build -t $LOCAL_IMAGE_NAME .'
}
}
stage('DeployLatest') {
when {
expression { return GIT_LOCAL_BRANCH.startsWith("develop") }
}
steps {
sh 'docker tag $LOCAL_IMAGE_NAME $LATEST_IMAGE_NAME'
sh 'docker push $LATEST_IMAGE_NAME'
sh 'ssh [email protected] "cd ~/compose && ./geoimagenet-compose.sh pull graphql && ./geoimagenet-compose.sh up --force-recreate -d graphql"'
slackSend channel: '#geoimagenet-dev', color: 'good', message: "*GeoImageNet GraphQL*:\nPushed docker image: `${env.LATEST_IMAGE_NAME}`\nDeployed to: https://geoimagenetdev.crim.ca"
}
}
stage('Deploy') {
when {
expression { return GIT_LOCAL_BRANCH.startsWith("release") }
}
steps {
sh 'docker tag $LOCAL_IMAGE_NAME $TAGGED_IMAGE_NAME'
sh 'docker push $TAGGED_IMAGE_NAME'
sh 'docker tag $LOCAL_IMAGE_NAME $LATEST_IMAGE_NAME'
sh 'docker push $LATEST_IMAGE_NAME'
sh 'ssh [email protected] "cd ~/compose && ./geoimagenet-compose.sh pull graphql && ./geoimagenet-compose.sh up --force-recreate -d graphql"'
slackSend channel: '#geoimagenet-dev', color: 'good', message: "*GeoImageNet graphql*:\nPushed docker image: `${env.TAGGED_IMAGE_NAME}`\nDeployed to: https://geoimagenetdev.crim.ca"
}
}
}
post {
success {
slackSend channel: '#geoimagenet-dev', color: 'good', message: "*GeoImageNet graphql*: Build #${env.BUILD_NUMBER} *successful* on git branch `${env.GIT_LOCAL_BRANCH}` :tada: (<${env.BUILD_URL}|View>)"
}
failure {
slackSend channel: '#geoimagenet-dev', color: 'danger', message: "*GeoImageNet graphql*: Build #${env.BUILD_NUMBER} *failed* on git branch `${env.GIT_LOCAL_BRANCH}` :sweat_smile: (<${env.BUILD_URL}|View>)"
}
}
}