forked from rafcollier/legend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
73 lines (71 loc) · 2.73 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
61
62
63
64
65
66
67
68
69
70
71
72
73
pipeline {
agent {
label "builder-base"
}
environment {
ORG = 'joule-cma'
APP_NAME = 'cmaj-legend'
}
stages {
stage('CI Build and push snapshot') {
when {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {
container('builder-base') {
sh "npm install"
sh "CI=true DISPLAY=:99 npm test"
sh "export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml"
sh "echo 'DEVELOPMENT RELEASE'"
sh "jx step post build --image $DOCKER_REGISTRY/cmaj/legend/legend-app:$PREVIEW_VERSION"
dir('./charts/preview') {
sh "make preview"
sh "jx preview --app $APP_NAME --dir ../.."
}
}
}
}
stage('Build Release') {
when {
branch 'master'
}
steps {
container('builder-base') {
// ensure we're not on a detached head
sh "git checkout master"
sh "git config --global credential.helper store"
sh "jx step git credentials"
//setup gcp service account access
withCredentials([string(credentialsId: 'google-cloud-service-account', variable: 'SERVICE_ACCOUNT_KEY')]) {
writeFile file: '/home/jenkins/workspace/Joule-CMA_CMAJ-Legend_master/key.json', text: SERVICE_ACCOUNT_KEY
sh "gcloud auth activate-service-account --key-file key.json"
}
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "jx step tag --version \$(cat VERSION)"
sh "npm install"
sh "echo 'PRODUCTION RELEASE'"
//sh "CI=true DISPLAY=:99 npm test"
sh "CI=true DISPLAY=:99"
sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml"
withCredentials([string(credentialsId: 'google-cloud-service-account-development-cluster', variable: 'SERVICE_ACCOUNT_KEY')]) {
writeFile file: '/home/jenkins/workspace/Joule-CMA_CMAJ-Legend_master/key-development.json', text: SERVICE_ACCOUNT_KEY
sh 'gcloud auth activate-service-account --key-file key-development.json'
sh 'gcloud container clusters get-credentials joule-development-can-ne-a-k8s --zone northamerica-northeast1-a --project joule-development-218113'
sh "kubectl set image deployment cmaj-legend cmaj-legend=gcr.io/joule-development-218113/cmaj/legend/legend-app:\$(cat VERSION) -n legend"
}
}
}
}
}
post {
always {
cleanWs()
}
}
}