forked from confluentinc/parallel-consumer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
65 lines (59 loc) · 2.89 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env groovy
//common {
// slackChannel = 'csid-build'
// nodeLabel = 'docker-openjdk13'
// runMergeCheck = false
//}
def RelaseTag = string(name: 'RELEASE_TAG', defaultValue: '',
description: 'Provide the tag of project that will be release to maven central,' +
'only use the value when you want to release to maven central')
def config = jobConfig {
owner = 'csid'
// testResultSpecs = ['junit': 'test/results.xml']
properties = [parameters([RelaseTag])]
slackChannel = 'csid-build'
nodeLabel = 'docker-debian-jdk17'
runMergeCheck = true
}
def job = {
def maven_command = sh(script: """if test -f "${env.WORKSPACE}/mvnw"; then echo "${env.WORKSPACE}/mvnw"; else echo "mvn"; fi""", returnStdout: true).trim()
// If we have a RELEASE_TAG specified as a build parameter, test that the version in pom.xml matches the tag.
if (!params.RELEASE_TAG.trim().equals('')) {
sh "git checkout ${params.RELEASE_TAG}"
def project_version = sh(
script: """${maven_command} help:evaluate -Dexpression=project.version -q -DforceStdout | tail -1""",
returnStdout: true
).trim()
if (!params.RELEASE_TAG.trim().equals(project_version)) {
echo 'ERROR: tag doesn\'t match project version, please correct and try again'
echo "Tag: ${params.RELEASE_TAG}"
echo "Project version: ${project_version}"
currentBuild.result = 'FAILURE'
return
}
}
stage('Build') {
archiveArtifacts artifacts: 'pom.xml'
withVaultEnv([["gpg/confluent-packaging-private-8B1DA6120C2BF624", "passphrase", "GPG_PASSPHRASE"]]) {
def mavenSettingsFile = "${env.WORKSPACE_TMP}/maven-global-settings.xml"
withMavenSettings("maven/jenkins_maven_global_settings", "settings", "MAVEN_GLOBAL_SETTINGS", mavenSettingsFile) {
withMaven(globalMavenSettingsFilePath: mavenSettingsFile) {
withDockerServer([uri: dockerHost()]) {
def isPrBuild = env.CHANGE_TARGET ? true : false
def buildPhase = isPrBuild ? "install" : "deploy"
if (params.RELEASE_TAG.trim().equals('')) {
sh "${maven_command} --batch-mode -Pjenkins -Pci -U dependency:analyze clean $buildPhase"
} else {
// it's a parameterized job, and we should deploy to maven central.
withGPGkey("gpg/confluent-packaging-private-8B1DA6120C2BF624") {
sh "${maven_command} --batch-mode clean deploy -P maven-central -Pjenkins -Pci -Dgpg.passphrase=$GPG_PASSPHRASE"
}
}
currentBuild.result = 'Success'
}
}
}
}
}
}
runJob config, job