forked from gothinkster/angular-realworld-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (58 loc) · 2.87 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
pipeline {
agent any
stages {
// stage('Test') {
// agent {
// docker {
// image 'node:12.7-alpine'
// args '-u root:root'
// }
// }
// steps {
// // should be ng test here, but that requires additional deps in this app's case
// sh "NODE_ENV=development npm install && ./node_modules/@angular/cli/bin/ng build"
// }
// }
stage('Get TBS-built image') {
agent {
docker {
image 'benjvi/kp'
}
}
steps {
withCredentials([file(credentialsId: 'tbs_kubeconfig', variable: 'KUBECONFIG')]) {
// build is most likely in-progress, so attachto the logs
// can get network issues here, continue if we get can error
sh "kp build logs angular-demo || true"
// check i we attached to the correct build and it completed successfully, if not retry
sh "sleep 3; ./scripts/ci/check-latest-image-build.sh || kp image trigger angular-demo || true"
sh "sleep 5; kp build logs angular-demo || true ; ./scripts/ci/check-latest-image-build.sh || true"
script {
IMG_VERSION = sh(script: "./scripts/ci/get-latest-image-version.sh", returnStdout: true)
}
}
}
}
stage('Deploy') {
agent {
docker {
image 'benjvi/prify'
args '-u root:root'
}
}
steps {
withCredentials(bindings: [sshUserPrivateKey(credentialsId: 'ssh-key-for-gitops', \
keyFileVariable: 'SSH_KEY_FOR_GITOPS')]) {
echo 'Deploying....'
sh "cd / && GIT_SSH_COMMAND='ssh -i $SSH_KEY_FOR_GITOPS -o IdentitiesOnly=yes -o StrictHostKeyChecking=no' git clone [email protected]:benjvi/apps-gitops.git"
sh "ls /apps-gitops"
sh "kustomize build k8s/base/ > /apps-gitops/nonprod-cluster/angular-app/ci-package.yml"
sh "cd /apps-gitops/nonprod-cluster/angular-app; kustomize create || true; kustomize edit add resource ci-package.yml; kustomize edit set image index.docker.io/benjvi/angular-demo=index.docker.io/benjvi/angular-demo@${IMG_VERSION}"
// need some details set in env for prify to work correctly
// not all context is kept between sh commands, so use a one liner
sh 'cd /apps-gitops/nonprod-cluster && git config user.email "jenkins@localhost" && git config user.name "Jenkins CI Bot - Angular" && GIT_SSH_COMMAND=\'ssh -i $SSH_KEY_FOR_GITOPS -o IdentitiesOnly=yes -o StrictHostKeyChecking=no\' prify run'
}
}
}
}
}