From b77aeda5ed0e2041d7a95b9d0da215397aafbfd3 Mon Sep 17 00:00:00 2001
From: abejan-bandwidth <84582213+abejan-bandwidth@users.noreply.github.com>
Date: Tue, 16 Nov 2021 19:21:18 +0200
Subject: [PATCH 1/2] Update Jenkinsfile
---
Jenkinsfile | 156 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 100 insertions(+), 56 deletions(-)
diff --git a/Jenkinsfile b/Jenkinsfile
index 760a1eb46..f13796efb 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,72 +1,116 @@
#!groovy
-def repo = 'zendesk-java-client'
+ARTIFACT_GENERATION_SLACK_CHANNEL = '#bwi-delivery-artifact-generation'
+def JOB_LABEL = 'regular'
properties(
- [
- [
- $class : 'BuildDiscarderProperty',
- strategy: [$class: 'LogRotator', numToKeepStr: '3']
- ],
- pipelineTriggers([pollSCM('H/5 * * * *')]),
- disableConcurrentBuilds(),
- ]
+ [
+ [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10']],
+ disableConcurrentBuilds(),
+ ]
)
-@NonCPS
-def getProjectKey(repo) {
- return repo + '_' + env.BRANCH_NAME.replaceAll("/", "_")
+def getRepositoryName() {
+ return scm.getUserRemoteConfigs()[0]?.getUrl().replaceFirst(/^.*\/([^\/]+?).git$/, '$1')
}
-def shouldPublish() {
- def snapshot = readMavenPom().version.contains('-SNAPSHOT')
- if (env.BRANCH_NAME == 'master' && !snapshot)
- {
- return true
- }
- else if (env.BRANCH_NAME != 'master' && snapshot)
- {
- return true
- }
- return false
+def getRevision() {
+ def matcher = readFile('pom.xml') =~ '(.+?)'
+ return matcher ? matcher[0][1] : null
}
-node('regular') {
- stage("Initial clean-up") {
- deleteDir()
- }
+def getChangelist() {
+ if (env.BRANCH_NAME == 'main') {
+ def matcher = readFile('pom.xml') =~ '(.+?)'
+ return matcher ? matcher[0][1] : ""
+ } else
+ return "-SNAPSHOT"
+}
+
+def getCommitSHA() {
+ return sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
+}
+
+def getSha1() {
+ if (env.BRANCH_NAME == 'main' && getChangelist() != '-SNAPSHOT')
+ return ""
+ else
+ return "-" + getCommitSHA();
+}
+
+pipeline {
+ agent {
+ label JOB_LABEL
+ }
+ options {
+ skipDefaultCheckout(true)
+ disableResume()
+ timeout(time: 30, unit: 'MINUTES')
+ }
+ stages {
+ stage('Checkout') {
+ steps {
+ checkout([
+ $class : 'GitSCM',
+ branches : scm.branches,
+ userRemoteConfigs: [[
+ url : scm.getUserRemoteConfigs()[0].getUrl(),
+ credentialsId: scm.getUserRemoteConfigs()[0].getCredentialsId(),
+ refspec : scm.getUserRemoteConfigs()[0].getRefspec() + ' +refs/heads/main:refs/remotes/origin/main'
+ ]],
+ extensions : [
+ [$class: 'CleanBeforeCheckout'],
+ [$class: 'CleanCheckout'],
+ [$class: 'CloneOption', depth: 0, noTags: true, honorRefspec: true, shallow: false]
+ ]
+ ])
+ }
+ }
+ stage('Run UT tests') {
+ steps {
+ withMaven(mavenSettingsConfig: 'maven_default_settings', options: [artifactsPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)], maven: 'maven') {
+ sh 'mvn clean package -T1C -fae'
- ws("workspace/${getProjectKey(repo)}")
- {
- try
- {
- stage("Checkout") {
- checkout scm
- }
- stage("Run UT/IT - ${getProjectKey(repo)}") {
- withMaven(options: [artifactsPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)], maven: 'maven') {
- sh "mvn -T 16C clean install -fae -U -q"
+ }
+ }
}
- }
- stage("Publish to nexus - ${getProjectKey(repo)}") {
- if (shouldPublish())
- {
- withMaven(options: [artifactsPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)], maven: 'maven') {
- sh "mvn clean deploy -DskipTests -fae -U -q -DnexusUrl=${NEXUS_URL}"
+ stage('Code analysis') {
+ steps {
+ withSonarQubeEnv('Sonar') {
+ withMaven(mavenSettingsConfig: 'maven_default_settings', options: [artifactsPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)], maven: 'maven') {
+ withEnv(["BRANCH_NAME=${env.BRANCH_NAME}"]) {
+ sh 'mvn sonar:sonar -Dsonar.branch.name=$BRANCH_NAME'
+ }
+ }
+ }
+ timeout(time: 30, unit: 'MINUTES') {
+ waitForQualityGate abortPipeline: true
+ }
}
}
- else
- {
- sh "echo 'Branch ${env.BRANCH_NAME} cannot publish this version of the artifact (only master can publish release version / other branches snapshots)'"
+ stage('Generating artifacts and pushing them to maven repository') {
+ steps {
+ withMaven(mavenSettingsConfig: 'maven_default_settings', options: [artifactsPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)], maven: 'maven') {
+ withEnv(["SHA1=${getSha1()}", "CHANGELIST=${getChangelist()}"]) {
+ withCredentials([usernamePassword(credentialsId: 'jfrog', usernameVariable: 'JFROG_USER', passwordVariable: 'JFROG_API_KEY')]) {
+ sh 'mvn clean deploy -T 1C -DskipTests -Dsha1=$SHA1 -Dchangelist=$CHANGELIST -DJFROG_USER=$JFROG_USER -DJFROG_API_KEY=$JFROG_API_KEY'
+ }
+ }
+ }
+ slackSend(
+ channel: "${ARTIFACT_GENERATION_SLACK_CHANNEL}",
+ color: "good",
+ message: "- All maven artifacts generated by the project ${getRepositoryName()} have been deployed (version ${getRevision()}${getSha1()}${getChangelist()}). " +
+ "You can browse the artifact deployed "
+ )
+ }
}
- }
}
- catch(e){
- throw e
- }
- finally {
- stage("Cleanup") {
- deleteDir()
- }
+ post {
+ always {
+ cleanWs()
+ dir("${env.WORKSPACE}@tmp") {
+ deleteDir()
+ }
+ }
}
- }
-}
\ No newline at end of file
+}
From 95c6e07ba53a5d2a0daea751b4854286c1a71f95 Mon Sep 17 00:00:00 2001
From: abejan-bandwidth <84582213+abejan-bandwidth@users.noreply.github.com>
Date: Tue, 16 Nov 2021 19:22:59 +0200
Subject: [PATCH 2/2] Update pom.xml
---
pom.xml | 104 +++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 81 insertions(+), 23 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5f343a62c..55ccdfa0f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,29 @@
com.cloudbees.thirdparty
zendesk-java-client
- 0.14.1-voxbone-0.0.3
+ ${revision}${sha1}${changelist}
+
+
+ 0.14.1-voxbone-0.0.3
+
+
+ bwi-zendesk-java-client
+
+ 1.8
+ 1.8
+
+
+ Dev :: Zendesk Java Client
+ ${revision}
+ ${basedir}/target/site/jacoco/jacoco.xml
+ ${project.basedir}/reports/coverage/lcov.info
+
+
+
+
+
+
+
zendesk-java-client
Java client for the Zendesk API
@@ -89,13 +111,6 @@
https://app.codeship.com/projects/302087
-
- 1.8
- 1.8
- voxbone-nexus
-
-
-
@@ -185,11 +200,9 @@
3.0.0-M3
- org.apache.maven.plugins
- maven-surefire-plugin
-
- 3
-
+ org.jfrog.buildinfo
+ artifactory-maven-plugin
+ ${maven-artifactory-plugin}
@@ -257,6 +270,44 @@
+
+ org.jfrog.buildinfo
+ artifactory-maven-plugin
+
+
+ build-info
+
+ publish
+
+
+
+ true
+ *password*,*secret*,*key*,*token*,*passphrase*
+ 60
+
+
+ ${project.groupId}
+ ${project.artifactId}
+ ${project.version}
+
+
+ https://bandwidth.jfrog.io/artifactory
+ ${JFROG_USER}
+ ${JFROG_API_KEY}
+ bwi-maven-local-prod
+ bwi-maven-local
+ true
+ true
+
+
+ ${artifact.name}
+ ${sha1}
+ {{BUILD_URL}}
+
+
+
+
+
@@ -298,15 +349,22 @@
-
-
- voxbone-nexus
- ${nexusUrl}/releases
-
-
- voxbone-nexus
- ${nexusUrl}/snapshots
-
-
+
+
+
+ bwi-maven-local
+ BWI Maven development repository
+ https://bandwidth.jfrog.io/artifactory/maven
+
+
+
+
+ false
+
+ bwi-maven-local-prod
+ BWI Maven production repository
+ https://bandwidth.jfrog.io/artifactory/maven-prod
+
+