From 186225040cb8dd2a8049f5c7dd17596c655f765b Mon Sep 17 00:00:00 2001 From: Andrew Pitt Date: Fri, 13 Dec 2019 12:05:45 -0500 Subject: [PATCH] Create Jenkinsfile Added Jenkinsfile --- Jenkinsfile | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..99dc4124b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,84 @@ +try { + def appName=env.APP_NAME + def gitSourceUrl=env.GIT_SOURCE_URL + def gitSourceRef=env.GIT_SOURCE_REF + def project="" + def projectVersion="" + node("maven") { + stage("Initialize") { + project = env.PROJECT_NAME + echo "appName: ${appName}" + echo "gitSourceUrl: ${gitSourceUrl}" + echo "gitSourceRef: ${gitSourceRef}" + } + stage("Checkout") { + echo "Checkout source." + git url: "${gitSourceUrl}", branch: "${gitSourceRef}" + echo "Read POM info." + pom = readMavenPom file: 'pom.xml' + projectVersion = pom.version + } + stage("Build JAR") { + echo "Build the app." + sh "mvn clean package" + } + stage("Quality Check") { + sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false" + sh "mvn sonar:sonar -Dsonar.jacoco.reportPaths=target/coverage-reports/jacoco-unit.exec -Dsonar.host.url=http://sonarqube.cicd.svc:9000" + // sh "mvn org.cyclonedx:cyclonedx-maven-plugin:makeBom" + //dependencyTrackPublisher(artifact: 'target/bom.xml', artifactType: 'bom', projectName: "${appName}", projectVersion: "${projectVersion}", synchronous: false) + } + stage("Build Image") { + echo "Build container image." + // unstash name:"jar" + openshift.withCluster() { + openshift.withProject('cicd') { + sh "oc start-build ${appName}-build --from-file=target/app.jar -n cicd --follow" + } + } + } + stage("Tag DEV") { + echo "Tag image to DEV" + openshift.withCluster() { + openshift.withProject('cicd') { + openshift.tag("${appName}:latest", "${appName}:dev") + } + } + } + stage("Deploy DEV") { + echo "Deploy to DEV." + openshift.withCluster() { + openshift.withProject("${appName}-dev") { + echo "Rolling out to DEV." + def dc = openshift.selector('dc', "${appName}") + dc.rollout().latest() + dc.rollout().status() + } + } + } + stage("Tag for QA") { + echo "Tag to UAT" + openshift.withCluster() { + openshift.withProject('cicd') { + openshift.tag("${appName}:dev", "${appName}:qa") + } + } + } + stage("Deploy QA") { + echo "Deploy to QA" + openshift.withCluster() { + openshift.withProject("${appName}-uat") { + echo "Rollout to QA." + def dc = openshift.selector('dc', "${appName}") + dc.rollout().latest() + dc.rollout().status() + } + } + } + } +} catch (err) { + echo "in catch block" + echo "Caught: ${err}" + currentBuild.result = 'FAILURE' + throw err +}