From 571d6f65cf5e0e5334956dbe11730fd47820b947 Mon Sep 17 00:00:00 2001 From: "LaMont, William (wl2432)" Date: Fri, 31 Aug 2018 10:56:17 -0400 Subject: initial code for cacher Issue-ID: AAI-1473 Change-Id: I8babe91e79f5c1e6e97b0f5b6dc827b8c5caec80 Signed-off-by: LaMont, William (wl2432) --- src/main/jenkins/Jenkinsfile | 31 +++++++++++++++++++++++++++++++ src/main/jenkins/build.groovy | 14 ++++++++++++++ src/main/jenkins/checkout.groovy | 14 ++++++++++++++ src/main/jenkins/deploy.groovy | 15 +++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 src/main/jenkins/Jenkinsfile create mode 100644 src/main/jenkins/build.groovy create mode 100644 src/main/jenkins/checkout.groovy create mode 100644 src/main/jenkins/deploy.groovy (limited to 'src/main/jenkins') diff --git a/src/main/jenkins/Jenkinsfile b/src/main/jenkins/Jenkinsfile new file mode 100644 index 0000000..c74d439 --- /dev/null +++ b/src/main/jenkins/Jenkinsfile @@ -0,0 +1,31 @@ +node ("${BUILD_SLAVE}") { + // get the jenkinsfile root directory + def rootDir = pwd() + + def JAVA_HOME = tool 'jdk180' + env.PATH = "${JAVA_HOME}/bin:${env.PATH}" + sh 'which java' + sh 'java -version' + + env.DOCKER_HOST="tcp://localhost:4243" + + // load external groovy scripts + def build + def checkout + def deploy + dir('tmp') { + git url: "${GIT_URL}", branch: "${GIT_BRANCH}" + checkout = load 'src/main/jenkins/checkout.groovy' + build = load 'src/main/jenkins/build.groovy' + deploy = load 'src/main/jenkins/deploy.groovy' + } + + // check out code from git + checkout.gitCheckout() + + // build the git project + build.buildProject() + + deploy.deployService() + +} \ No newline at end of file diff --git a/src/main/jenkins/build.groovy b/src/main/jenkins/build.groovy new file mode 100644 index 0000000..3170510 --- /dev/null +++ b/src/main/jenkins/build.groovy @@ -0,0 +1,14 @@ + + +def buildProject() { + stage 'Build Git Project' + wrap([$class: 'ConfigFileBuildWrapper', managedFiles: [[fileId: 'eb0c7cc1-e851-4bc2-9401-2680c225f88c', targetLocation: '', variable: 'MAVEN_SETTINGS']]]) { + mvn '-s $MAVEN_SETTINGS -f pom.xml' +} +} + +def mvn(args) { + sh "${tool 'maven3'}/bin/mvn ${args} ${MAVEN_GOALS}" +} + +return this \ No newline at end of file diff --git a/src/main/jenkins/checkout.groovy b/src/main/jenkins/checkout.groovy new file mode 100644 index 0000000..ed439ec --- /dev/null +++ b/src/main/jenkins/checkout.groovy @@ -0,0 +1,14 @@ + +def gitCheckout() { + stage 'Checkout GIT' + //different ways to checkout + //checkout from master + //git "url: ${GIT_URL}, branch: ${GIT_BRANCH}" + //checkout from branch hardcoding" + //git branch: 'jenkins_deploy_test', credentialsId: 'b9bbafe5-53ce-4d2c-8b84-09137f75c592', url: 'https://codecloud.web.att.com/scm/st_ocnp/sdk-java-starter.git' + //checkout from branch parameters with credentials + //git branch: "${GIT_BRANCH}", credentialsId: 'b9bbafe5-53ce-4d2c-8b84-09137f75c592', url: "${GIT_URL}" + //checkout from branch parameters with no credentials + git branch: "${GIT_BRANCH}", url: "${GIT_URL}" +} +return this \ No newline at end of file diff --git a/src/main/jenkins/deploy.groovy b/src/main/jenkins/deploy.groovy new file mode 100644 index 0000000..1a000e3 --- /dev/null +++ b/src/main/jenkins/deploy.groovy @@ -0,0 +1,15 @@ +def deployService(){ + stage 'Deploying Service' + + // get the jenkinsfile root directory + def ROOT_DIR = pwd() + ROOT_DIR = "${ROOT_DIR}"+'/src/main/kubernetes' + echo "ROOTDIR : ${ROOT_DIR}" + sh "/opt/app/kubernetes/v1.3.4/bin/kubectl --kubeconfig=${ROOT_DIR}/kubectl.conf replace --force --cascade -f ${ROOT_DIR}/${artifactId}-svc.yaml" + sh "/opt/app/kubernetes/v1.3.4/bin/kubectl --kubeconfig=${ROOT_DIR}/kubectl.conf replace --force --cascade -f ${ROOT_DIR}/${artifactId}-rc.yaml" +} +return this + + + + -- cgit 1.2.3-korg