Skip to content
This repository was archived by the owner on Nov 17, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 100 additions & 56 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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') =~ '<revision>(.+?)</revision>'
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') =~ '<changelist>(.+?)</changelist>'
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 <https://bandwidth.jfrog.io/artifactory/webapp/builds/${getRepositoryName()}/${getCommitSHA()}|here>"
)
}
}
}
}
catch(e){
throw e
}
finally {
stage("Cleanup") {
deleteDir()
}
post {
always {
cleanWs()
dir("${env.WORKSPACE}@tmp") {
deleteDir()
}
}
}
}
}
}
104 changes: 81 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@

<groupId>com.cloudbees.thirdparty</groupId>
<artifactId>zendesk-java-client</artifactId>
<version>0.14.1-voxbone-0.0.3</version>
<version>${revision}${sha1}${changelist}</version>

<properties>
<revision>0.14.1-voxbone-0.0.3</revision>
<sha1></sha1>
<changelist></changelist>
<artifact.name>bwi-zendesk-java-client</artifact.name>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<!-- Sonar analysis configuration -->
<sonar.projectName>Dev :: Zendesk Java Client</sonar.projectName>
<sonar.projectVersion>${revision}</sonar.projectVersion>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.javascript.lcov.reportPaths>${project.basedir}/reports/coverage/lcov.info</sonar.javascript.lcov.reportPaths>
<sonar.exclusions>
</sonar.exclusions>
<sonar.coverage.exclusions>
</sonar.coverage.exclusions>
<sonar.cpd.exclusions>
</sonar.cpd.exclusions>
</properties>

<name>zendesk-java-client</name>
<description>Java client for the Zendesk API</description>
Expand Down Expand Up @@ -89,13 +111,6 @@
<url>https://app.codeship.com/projects/302087</url>
</ciManagement>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<serverId>voxbone-nexus</serverId>
<nexusUrl></nexusUrl>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -185,11 +200,9 @@
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<rerunFailingTestsCount>3</rerunFailingTestsCount>
</configuration>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>${maven-artifactory-plugin}</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -257,6 +270,44 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<artifactory>
<includeEnvVars>true</includeEnvVars>
<envVarsExcludePatterns>*password*,*secret*,*key*,*token*,*passphrase*</envVarsExcludePatterns>
<timeoutSec>60</timeoutSec>
</artifactory>
<deployProperties>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</deployProperties>
<publisher>
<contextUrl>https://bandwidth.jfrog.io/artifactory</contextUrl>
<username>${JFROG_USER}</username>
<password>${JFROG_API_KEY}</password>
<repoKey>bwi-maven-local-prod</repoKey>
<snapshotRepoKey>bwi-maven-local</snapshotRepoKey>
<publishArtifacts>true</publishArtifacts>
<publishBuildInfo>true</publishBuildInfo>
</publisher>
<buildInfo>
<buildName>${artifact.name}</buildName>
<buildNumber>${sha1}</buildNumber>
<buildUrl>{{BUILD_URL}}</buildUrl>
</buildInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -298,15 +349,22 @@
</profile>
</profiles>

<distributionManagement>
<repository>
<id>voxbone-nexus</id>
<url>${nexusUrl}/releases</url>
</repository>
<snapshotRepository>
<id>voxbone-nexus</id>
<url>${nexusUrl}/snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<snapshots/>
<id>bwi-maven-local</id>
<name>BWI Maven development repository</name>
<url>https://bandwidth.jfrog.io/artifactory/maven</url>
</repository>

<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bwi-maven-local-prod</id>
<name>BWI Maven production repository</name>
<url>https://bandwidth.jfrog.io/artifactory/maven-prod</url>
</repository>
</repositories>

</project>