Skip to content

Commit

Permalink
Merge pull request #72 from stephenashank/feature/cicd
Browse files Browse the repository at this point in the history
Onboard OAuth plugin in team CI server.
  • Loading branch information
Stephen Shank committed Oct 9, 2019
2 parents b140a9e + 080307e commit f6e1010
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
54 changes: 52 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
// Build the plugin using https://github.com/jenkins-infra/pipeline-library
buildPlugin(platforms: ['linux'], jenkinsVersions: [null, '2.107.2'], failFast: false)
/*
* Copyright 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pipeline {
agent {
kubernetes {
cloud 'kubernetes'
label 'maven-pod'
yamlFile 'jenkins/maven-pod.yaml'
}
}

environment {
GOOGLE_PROJECT_ID = "${OAUTH_IT_PROJECT_ID}"
BUILD_ARTIFACTS_BUCKET = "${OAUTH_IT_BUCKET}"
BUILD_ARTIFACTS = "build-${BRANCH_NAME}-${BUILD_ID}.tar.gz"
}

stages {
stage("Build and test") {
steps {
container('maven') {
withCredentials([[$class: 'StringBinding', credentialsId: env.OAUTH_IT_CRED_ID, variable: 'GOOGLE_CREDENTIALS']]) {
catchError {
// build
sh "mvn clean package -ntp"

// run tests
sh "mvn verify -ntp"
}

sh "jenkins/saveAndCompress.sh"
step([$class: 'ClassicUploadStep', credentialsId: env.OAUTH_BUCKET_CRED_ID, bucket: "gs://${BUILD_ARTIFACTS_BUCKET}", pattern: env.BUILD_ARTIFACTS])
}
}
}
}
}
}

22 changes: 22 additions & 0 deletions jenkins/maven-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.6.2-jdk-8
command: ['cat']
tty: true
33 changes: 33 additions & 0 deletions jenkins/saveAndCompress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
pwd
mkdir result

# The files will only exist if maven reaches the corresponding phase of the build
function cpe() {
if [[ -e target/$1 ]]; then
cp -rv target/$1 result
else
echo "target/$1 not copied, check the completed build phases."
fi
}

# Copy over the important artifacts
cpe google-oauth-plugin.hpi
cpe failsafe-reports
cpe surefire-reports

# Compress the artifacts for upload
tar -zcvf ${BUILD_ARTIFACTS} result

0 comments on commit f6e1010

Please sign in to comment.