Skip to content

Commit

Permalink
Merge pull request #33 from GoogleCloudPlatform/tf-12-container
Browse files Browse the repository at this point in the history
Use tf12 container version
  • Loading branch information
Chris Love authored Aug 13, 2019
2 parents 477cf4e + b8e9ce2 commit 22d684f
Showing 1 changed file with 63 additions and 81 deletions.
144 changes: 63 additions & 81 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,92 +22,74 @@ limitations under the License.
// Reference: https://github.com/jenkinsci/kubernetes-plugin

// set up pod label and GOOGLE_APPLICATION_CREDENTIALS (for Terraform)
def label = "k8s-infra"
def containerName = "k8s-node"
def GOOGLE_APPLICATION_CREDENTIALS = '/home/jenkins/dev/jenkins-deploy-dev-infra.json'
def containerName = "tracing"
def GOOGLE_APPLICATION_CREDENTIALS = '/home/jenkins/dev/jenkins-deploy-dev-infra.json'
def jenkins_container_version = env.JENKINS_CONTAINER_VERSION

podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins: build-node
spec:
containers:
- name: ${containerName}
image: gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${env.JENKINS_CONTAINER_VERSION}
command: ['cat']
tty: true
volumeMounts:
# Mount the dev service account key
- name: dev-key
mountPath: /home/jenkins/dev
resources:
limits:
cpu: 2
memory: 2Gi
requests:
cpu: 1
memory: 1Gi
volumes:
# Create a volume that contains the dev json key that was saved as a secret
- name: dev-key
secret:
secretName: jenkins-deploy-dev-infra
"""
) {
node(label) {
try {
// Options covers all other job properties or wrapper functions that apply to entire Pipeline.
properties([disableConcurrentBuilds()])
// set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
env.GOOGLE_APPLICATION_CREDENTIALS=GOOGLE_APPLICATION_CREDENTIALS
podTemplate(
containers: [
containerTemplate(name: "${containerName}",
image: "gcr.io/pso-helmsman-cicd/jenkins-k8s-node:${jenkins_container_version}",
command: 'tail -f /dev/null',
resourceRequestCpu: '1000m',
resourceLimitCpu: '2000m',
resourceRequestMemory: '1Gi',
resourceLimitMemory: '2Gi'
)
],
volumes: [secretVolume(mountPath: '/home/jenkins/dev',
secretName: 'jenkins-deploy-dev-infra'
)]
) {
node(POD_LABEL) {
try {
// Options covers all other job properties or wrapper functions that apply to entire Pipeline.
properties([disableConcurrentBuilds()])
// set env variable GOOGLE_APPLICATION_CREDENTIALS for Terraform
env.GOOGLE_APPLICATION_CREDENTIALS = GOOGLE_APPLICATION_CREDENTIALS

stage('Setup') {
container(containerName) {
// checkout code from scm i.e. commits related to the PR
checkout scm
stage('Setup') {
container(containerName) {
// checkout code from scm i.e. commits related to the PR
checkout scm

// Setup gcloud service account access
sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}"
sh "gcloud config set compute/zone ${env.ZONE}"
sh "gcloud config set core/project ${env.PROJECT_ID}"
sh "gcloud config set compute/region ${env.REGION}"
}
}
stage('Lint') {
container(containerName) {
sh "make lint"
}
}
// Setup gcloud service account access
sh "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}"
sh "gcloud config set compute/zone ${env.ZONE}"
sh "gcloud config set core/project ${env.PROJECT_ID}"
sh "gcloud config set compute/region ${env.REGION}"
}
}
stage('Lint') {
container(containerName) {
sh "make lint"
}
}

stage('Create') {
container(containerName) {
sh "make create"
}
}
stage('Create') {
container(containerName) {
sh "make create"
}
}

stage('Validate') {
container(containerName) {
sh "make validate"
}
}

stage('Validate') {
container(containerName) {
sh "make validate"
} catch (err) {
// if any exception occurs, mark the build as failed
// and display a detailed message on the Jenkins console output
currentBuild.result = 'FAILURE'
echo "FAILURE caught echo ${err}"
throw err
} finally {
stage('Teardown') {
container(containerName) {
sh "make teardown"
}
}
}
}

}
catch (err) {
// if any exception occurs, mark the build as failed
// and display a detailed message on the Jenkins console output
currentBuild.result = 'FAILURE'
echo "FAILURE caught echo ${err}"
throw err
}
finally {
stage('Teardown') {
container(containerName) {
sh "make teardown"
sh "gcloud auth revoke"
}
}
}
}
}

0 comments on commit 22d684f

Please sign in to comment.