forked from jaraxasoftware/gorush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
150 lines (144 loc) · 5.55 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@Library('devops-tools')
import org.netscale.jenkins.slack.SlackNotifier
pipeline {
agent {
label "jenkins-go"
}
environment {
SLACK_CHANNEL = 'dkv-bots'
SLACK_DOMAIN = 'jaraxa'
SLACK_CREDENTIALS = 'slack-netcomp-devops'
CHANGE_LIST = true
TEST_SUMMARY = true
ORG = 'netscale-technologies'
APP_NAME = 'gorush'
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
DOCKER_REGISTRY_ORG = 'netscale-technologies'
PROMOTE_ENV_NAME = 'environment-dkv-preprod'
CI_BRANCH_DEV = 'develop'
CI_BRANCH_UAT = 'staging'
CI_BRANCH_PROD = 'release'
}
stages {
stage('Build Preview for develop') {
when {
branch 'develop'
}
environment {
DEVELOP_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
PREVIEW_VERSION = "$DEVELOP_VERSION"
DEVELOP_NAMESPACE = "jx-dkv-develop"
HELM_RELEASE = "$DEVELOP_NAMESPACE".toLowerCase()
}
steps {
container('go') {
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush') {
checkout scm: [$class: 'GitSCM', branches: [[name: '*/develop']], userRemoteConfigs: [[credentialsId: 'jx-pipeline-git-github-github.com', url: 'https://github.com/netscale-technologies/gorush']]]
sh 'make get'
sh 'make build_linux_amd64'
sh "export VERSION=$DEVELOP_VERSION && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$DEVELOP_VERSION"
}
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush/charts/develop') {
sh "make preview"
sh "jx preview --app $APP_NAME --namespace $DEVELOP_NAMESPACE --name $PROMOTE_ENV_NAME --alias $APP_NAME --label $APP_NAME --release $APP_NAME --no-comment --no-poll --no-wait --dir ../.."
}
}
}
}
stage('Build Release for Staging/UAT') {
when {
branch 'staging'
}
environment {
UAT_VERSION = "RELEASE-$BUILD_NUMBER"
}
steps {
container('go') {
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush') {
checkout scm: [$class: 'GitSCM', branches: [[name: '*/staging']], userRemoteConfigs: [[credentialsId: 'jx-pipeline-git-github-github.com', url: 'https://github.com/netscale-technologies/gorush']]]
// ensure we're not on a detached head
sh "git checkout $CI_BRANCH_UAT"
sh "git config --global credential.helper store"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "jx step tag --version \$(cat VERSION) --charts-dir ./charts/gorush/"
sh 'make get'
sh 'make build_linux_amd64'
sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
}
stage('Build Release for Production') {
when {
branch 'release'
}
steps {
container('go') {
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush') {
checkout scm: [$class: 'GitSCM', branches: [[name: '*/release']], userRemoteConfigs: [[credentialsId: 'jx-pipeline-git-github-github.com', url: 'https://github.com/netscale-technologies/gorush']]]
// ensure we're not on a detached head
sh "git checkout $CI_BRANCH_PROD"
sh "git config --global credential.helper store"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
sh "jx step tag --version \$(cat VERSION) --charts-dir ./charts/gorush/"
sh 'make get'
sh 'make build_linux_amd64'
sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml"
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}
}
stage('Promote to staging/UAT environment') {
when {
branch 'staging'
}
environment {
REMOTE_ENV_NAME = 'jx-dkv-remote-preprod-legacy'
}
steps {
container('go') {
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush/charts/gorush') {
// release the helm chart
sh "jx step helm release"
// promote through promotion Environment
sh "jx promote -b --ignore-local-file=true --app $APP_NAME --timeout 1h --version \$(cat ../../VERSION) --env $REMOTE_ENV_NAME --verbose"
}
}
}
}
stage('Promote to Production environment') {
when {
branch 'release'
}
environment {
PROD_ENV_NAME = 'jx-dkv-remote-legacy'
}
steps {
container('go') {
dir('/home/jenkins/agent/src/github.com/netscale-technologies/gorush/charts/gorush') {
sh "jx step changelog --version v\$(cat ../../VERSION)"
// release the helm chart
sh "jx step helm release"
// promote through promotion Environment
sh "jx promote -b --ignore-local-file --app $APP_NAME --timeout 1h --version \$(cat ../../VERSION) --env $PROD_ENV_NAME"
}
}
}
}
}
post {
always {
script {
new SlackNotifier().notifyResultFull()
}
cleanWs()
}
}
}