Skip to content

Commit 22d684f

Browse files
author
Chris Love
authored
Merge pull request #33 from GoogleCloudPlatform/tf-12-container
Use tf12 container version
2 parents 477cf4e + b8e9ce2 commit 22d684f

File tree

1 file changed

+63
-81
lines changed

1 file changed

+63
-81
lines changed

Jenkinsfile

Lines changed: 63 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,92 +22,74 @@ limitations under the License.
2222
// Reference: https://github.com/jenkinsci/kubernetes-plugin
2323

2424
// 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'
25+
def containerName = "tracing"
26+
def GOOGLE_APPLICATION_CREDENTIALS = '/home/jenkins/dev/jenkins-deploy-dev-infra.json'
27+
def jenkins_container_version = env.JENKINS_CONTAINER_VERSION
2828

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.JENKINS_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-
resources:
46-
limits:
47-
cpu: 2
48-
memory: 2Gi
49-
requests:
50-
cpu: 1
51-
memory: 1Gi
52-
volumes:
53-
# Create a volume that contains the dev json key that was saved as a secret
54-
- name: dev-key
55-
secret:
56-
secretName: jenkins-deploy-dev-infra
57-
"""
58-
) {
59-
node(label) {
60-
try {
61-
// Options covers all other job properties or wrapper functions that apply to entire Pipeline.
62-
properties([disableConcurrentBuilds()])
63-
// set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
64-
env.GOOGLE_APPLICATION_CREDENTIALS=GOOGLE_APPLICATION_CREDENTIALS
29+
podTemplate(
30+
containers: [
31+
containerTemplate(name: "${containerName}",
32+
image: "gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${jenkins_container_version}",
33+
command: 'tail -f /dev/null',
34+
resourceRequestCpu: '1000m',
35+
resourceLimitCpu: '2000m',
36+
resourceRequestMemory: '1Gi',
37+
resourceLimitMemory: '2Gi'
38+
)
39+
],
40+
volumes: [secretVolume(mountPath: '/home/jenkins/dev',
41+
secretName: 'jenkins-deploy-dev-infra'
42+
)]
43+
) {
44+
node(POD_LABEL) {
45+
try {
46+
// Options covers all other job properties or wrapper functions that apply to entire Pipeline.
47+
properties([disableConcurrentBuilds()])
48+
// set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
49+
env.GOOGLE_APPLICATION_CREDENTIALS = GOOGLE_APPLICATION_CREDENTIALS
6550

66-
stage('Setup') {
67-
container(containerName) {
68-
// checkout code from scm i.e. commits related to the PR
69-
checkout scm
51+
stage('Setup') {
52+
container(containerName) {
53+
// checkout code from scm i.e. commits related to the PR
54+
checkout scm
7055

71-
// Setup gcloud service account access
72-
sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}"
73-
sh "gcloud config set compute/zone ${env.ZONE}"
74-
sh "gcloud config set core/project ${env.PROJECT_ID}"
75-
sh "gcloud config set compute/region ${env.REGION}"
76-
}
77-
}
78-
stage('Lint') {
79-
container(containerName) {
80-
sh "make lint"
81-
}
82-
}
56+
// Setup gcloud service account access
57+
sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}"
58+
sh "gcloud config set compute/zone ${env.ZONE}"
59+
sh "gcloud config set core/project ${env.PROJECT_ID}"
60+
sh "gcloud config set compute/region ${env.REGION}"
61+
}
62+
}
63+
stage('Lint') {
64+
container(containerName) {
65+
sh "make lint"
66+
}
67+
}
8368

84-
stage('Create') {
85-
container(containerName) {
86-
sh "make create"
87-
}
88-
}
69+
stage('Create') {
70+
container(containerName) {
71+
sh "make create"
72+
}
73+
}
74+
75+
stage('Validate') {
76+
container(containerName) {
77+
sh "make validate"
78+
}
79+
}
8980

90-
stage('Validate') {
91-
container(containerName) {
92-
sh "make validate"
81+
} catch (err) {
82+
// if any exception occurs, mark the build as failed
83+
// and display a detailed message on the Jenkins console output
84+
currentBuild.result = 'FAILURE'
85+
echo "FAILURE caught echo ${err}"
86+
throw err
87+
} finally {
88+
stage('Teardown') {
89+
container(containerName) {
90+
sh "make teardown"
91+
}
92+
}
9393
}
9494
}
95-
96-
}
97-
catch (err) {
98-
// if any exception occurs, mark the build as failed
99-
// and display a detailed message on the Jenkins console output
100-
currentBuild.result = 'FAILURE'
101-
echo "FAILURE caught echo ${err}"
102-
throw err
103-
}
104-
finally {
105-
stage('Teardown') {
106-
container(containerName) {
107-
sh "make teardown"
108-
sh "gcloud auth revoke"
109-
}
110-
}
111-
}
112-
}
11395
}

0 commit comments

Comments
 (0)