1
1
#! /usr/bin/env groovy
2
+
2
3
/*
3
4
Copyright 2018 Google LLC
4
5
@@ -13,94 +14,75 @@ distributed under the License is distributed on an "AS IS" BASIS,
13
14
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
15
See the License for the specific language governing permissions and
15
16
limitations under the License.
16
-
17
17
*/
18
18
19
- // The declarative agent is defined in yaml. It was previously possible to
20
- // define containerTemplate but that has been deprecated in favor of the yaml
21
- // format
22
19
// Reference: https://github.com/jenkinsci/kubernetes-plugin
23
-
24
20
// set up pod label and GOOGLE_APPLICATION_CREDENTIALS (for Terraform)
25
- def label = " k8s-infra"
26
- def containerName = " k8s-node"
27
- def GOOGLE_APPLICATION_CREDENTIALS = ' /home/jenkins/dev/jenkins-deploy-dev-infra.json'
28
-
29
- podTemplate(label : label, yaml : """
30
- apiVersion: v1
31
- kind: Pod
32
- metadata:
33
- labels:
34
- jenkins: build-node
35
- spec:
36
- containers:
37
- - name: ${ containerName}
38
- image: gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${ env.CONTAINER_VERSION}
39
- command: ['cat']
40
- tty: true
41
- volumeMounts:
42
- # Mount the dev service account key
43
- - name: dev-key
44
- mountPath: /home/jenkins/dev
45
- volumes:
46
- # Create a volume that contains the dev json key that was saved as a secret
47
- - name: dev-key
48
- secret:
49
- secretName: jenkins-deploy-dev-infra
50
- """
51
- ) {
52
- node(label) {
53
- try {
54
- // Options covers all other job properties or wrapper functions that apply to entire Pipeline.
55
- properties([disableConcurrentBuilds()])
56
- // set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
57
- env. GOOGLE_APPLICATION_CREDENTIALS = GOOGLE_APPLICATION_CREDENTIALS
58
-
59
- stage(' Setup' ) {
60
- container(containerName) {
61
- // checkout code from scm i.e. commits related to the PR
62
- checkout scm
21
+ def containerName = " cloud-sql-postgres"
22
+ def GOOGLE_APPLICATION_CREDENTIALS = ' /home/jenkins/dev/jenkins-deploy-dev-infra.json'
23
+ def jenkins_container_version = env. JENKINS_CONTAINER_VERSION
63
24
64
- // Setup gcloud service account access
65
- sh " gcloud auth activate-service-account --key-file=${ GOOGLE_APPLICATION_CREDENTIALS} "
66
- sh " gcloud config set compute/zone ${ env.CLUSTER_ZONE} "
67
- sh " gcloud config set core/project ${ env.PROJECT_ID} "
68
- sh " gcloud config set compute/region ${ env.REGION} "
69
- }
70
- }
71
- stage(' Lint' ) {
72
- container(containerName) {
73
- sh " make lint"
74
- }
75
- }
25
+ podTemplate(
26
+ containers : [
27
+ containerTemplate(name : " ${ containerName} " ,
28
+ image : " gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${ jenkins_container_version} " ,
29
+ command : ' tail -f /dev/null' ,
30
+ resourceRequestCpu : ' 1000m' ,
31
+ resourceLimitCpu : ' 2000m' ,
32
+ resourceRequestMemory : ' 1Gi' ,
33
+ resourceLimitMemory : ' 2Gi'
34
+ )
35
+ ],
36
+ volumes : [secretVolume(mountPath : ' /home/jenkins/dev' ,
37
+ secretName : ' jenkins-deploy-dev-infra'
38
+ )]
39
+ ) {
40
+ node(POD_LABEL ) {
41
+ try {
42
+ // Options covers all other job properties or wrapper functions that apply to entire Pipeline.
43
+ properties([disableConcurrentBuilds()])
44
+ // set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
45
+ env. GOOGLE_APPLICATION_CREDENTIALS = GOOGLE_APPLICATION_CREDENTIALS
76
46
77
- stage(' Create' ) {
78
- container(containerName) {
79
- sh " make create"
80
- }
81
- }
47
+ stage(' Setup' ) {
48
+ container(containerName) {
49
+ // checkout code from scm i.e. commits related to the PR
50
+ checkout scm
82
51
83
- stage(' Validate' ) {
84
- container(containerName) {
85
- sh " make validate"
52
+ // Setup gcloud service account access
53
+ sh " gcloud auth activate-service-account --key-file=${ GOOGLE_APPLICATION_CREDENTIALS} "
54
+ sh " gcloud config set compute/zone ${ env.CLUSTER_ZONE} "
55
+ sh " gcloud config set core/project ${ env.PROJECT_ID} "
56
+ sh " gcloud config set compute/region ${ env.REGION} "
57
+ }
58
+ }
59
+ stage(' Lint' ) {
60
+ container(containerName) {
61
+ sh " make lint"
62
+ }
63
+ }
64
+ stage(' Create' ) {
65
+ container(containerName) {
66
+ sh " make create"
67
+ }
68
+ }
69
+ stage(' Validate' ) {
70
+ container(containerName) {
71
+ sh " make validate"
72
+ }
73
+ }
74
+ } catch (err) {
75
+ // if any exception occurs, mark the build as failed
76
+ // and display a detailed message on the Jenkins console output
77
+ currentBuild. result = ' FAILURE'
78
+ echo " FAILURE caught echo ${ err} "
79
+ throw err
80
+ } finally {
81
+ stage(' Teardown' ) {
82
+ container(containerName) {
83
+ sh " make teardown"
84
+ }
85
+ }
86
86
}
87
87
}
88
-
89
- }
90
- catch (err) {
91
- // if any exception occurs, mark the build as failed
92
- // and display a detailed message on the Jenkins console output
93
- currentBuild. result = ' FAILURE'
94
- echo " FAILURE caught echo ${ err} "
95
- throw err
96
- }
97
- finally {
98
- stage(' Teardown' ) {
99
- container(containerName) {
100
- sh " make teardown"
101
- sh " gcloud auth revoke"
102
- }
103
- }
104
- }
105
- }
106
88
}
0 commit comments