-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
57 lines (56 loc) · 1.98 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
def dockerHubRepo = "ihcc/dac-api"
def githubRepo = "ihcc-cohorts/dac-api"
def commit = "UNKNOWN"
def version = "UNKNOWN"
pipeline {
agent any
stages {
stage('Prepare') {
steps {
script {
commit = sh(returnStdout: true, script: 'git describe --always').trim()
}
script {
version = sh(returnStdout: true, script: 'cat ./package.json | grep \\"version\\" | cut -d \':\' -f2 | sed -e \'s/"//\' -e \'s/",//\'').trim()
}
}
}
stage('Build container') {
steps {
sh "docker build -f Dockerfile . -t ${dockerHubRepo}:${commit}"
}
}
stage('Pushes edge image') {
when {
branch "develop"
}
steps {
withCredentials([usernamePassword(credentialsId:'dac_dockerhub_user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
sh "docker tag ${dockerHubRepo}:${commit} ${dockerHubRepo}:edge"
sh "docker push ${dockerHubRepo}:${commit}"
sh "docker push ${dockerHubRepo}:edge"
}
}
}
stage('Pushes latest image') {
when {
branch "master"
}
steps {
withCredentials([
usernamePassword(credentialsId:'dac_dockerhub_user', usernameVariable: 'DOCKERHUB_USERNAME', passwordVariable: 'DOCKERHUB_PASSWORD'),
usernamePassword(credentialsId:'github', usernameVariable: 'GITHUB_USERNAME', passwordVariable: 'GITHUB_PASSWORD'),
]) {
sh "git tag ${version}"
sh "git push https://${GITHUB_USERNAME}:${GITHUB_PASSWORD}@github.com/${githubRepo} --tags"
sh 'docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD'
sh "docker tag ${dockerHubRepo}:${commit} ${dockerHubRepo}:latest"
sh "docker tag ${dockerHubRepo}:${commit} ${dockerHubRepo}:${version}"
sh "docker push ${dockerHubRepo}:latest"
sh "docker push ${dockerHubRepo}:${version}"
}
}
}
}
}