-
Notifications
You must be signed in to change notification settings - Fork 3
/
maven-Jenkinsfile
158 lines (135 loc) · 5.31 KB
/
maven-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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env groovy
/**
* Jenkinsfile for zanata-scripts
*/
@Field
public static final String PROJ_URL = 'https://github.com/zanata/zanata-scripts'
// TODO: restore to master
@Field
public static final String ZANATA_SCRIPTS_BRANCH = 'ZNTA-1803-maven-release-pipeline'
@Field
public static final String ARTIFACT_ID = "platform"
// The projects that provides version (the others just use project.version)
@Field
public static final String MAVEN_VERSION_PROJECTS = 'build-tools,parent'
// The projects to be release to nexus
@Field
public static final String NEXUS_RELEASE_PROJECTS = '!server/zanata-test-war,!server/functional-test'
@Field
public static final String MAVEN_RELEASE_OPTIONS = "-Dallow.deploy.skip=false -Dcheckstyle.skip=true " +
"-Denforcer.skip=true -Dfindbugs.skip=true " +
"-Dgpg.executable=gpg2 -Dgpg.useagent=true " +
"-Doptimise "+
"-DskipArqTests=true -DskipFuncTests=true -DskipTests=true " +
"-DupdateReleaseInfo=true " +
"-Prelease"
@Field
public static final String PIPELINE_LIBRARY_BRANCH = 'v0.3.1'
@Library('github.com/zanata/zanata-pipeline-library@v0.3.1')
import org.zanata.jenkins.Notifier
import org.zanata.jenkins.PullRequests
import org.zanata.jenkins.ScmGit
import static org.zanata.jenkins.StackTraces.getStackTrace
import groovy.transform.Field
@Field
def pipelineLibraryScmGit
@Field
def mainScmGit
@Field
def notify
@Field
def jobName
timestamps {
// We need a node with release label
node('release') {
ansiColor('xterm') {
pipelineLibraryScmGit = new ScmGit(env, steps, 'https://github.com/zanata/zanata-pipeline-library')
pipelineLibraryScmGit.init(PIPELINE_LIBRARY_BRANCH)
mainScmGit = new ScmGit(env, steps, PROJ_URL)
mainScmGit.init(ZANATA_SCRIPTS_BRANCH)
notify = new Notifier(env, steps, currentBuild,
pipelineLibraryScmGit, mainScmGit, (env.GITHUB_COMMIT_CONTEXT) ?: 'Jenkinsfile',
)
jobName = env.JOB_NAME
def projectProperties = [
[
$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator',
numToKeepStr: '20', // keep records for at most X builds
artifactDaysToKeepStr: '', // keep artifacts no more than X days
artifactNumToKeepStr: '10', // keep artifacts for at most X builds
]
],
[$class: 'GithubProjectProperty',
projectUrlStr: PROJ_URL
],
[$class: 'ParametersDefinitionProperty',
parameterDefinitions: [
[$class: 'LabelParameterDefinition',
// Specify the default node in Jenkins env var DEFAULT_NODE
// (eg kvm), or leave blank to build on any node.
defaultValue: defaultNodeLabel,
description: 'Jenkins node label to use for build',
name: 'LABEL'
],
[$class: 'StringParameterDefinition',
defaultValue: 'auto',
description: 'Version to release like "4.4.0", "4.4.0-alpha-1", or "auto" to release the SNAPSHOT',
name: 'RELEASE_VERSION'
],
[$class: 'StringParameterDefinition',
defaultValue: '-T 1',
description: 'Maven extra options',
name: 'MAVEN_EXTRA_OPTIONS'
],
]
],
]
properties(projectProperties)
}
stage('Prepare') {
// Checkout and test GPG
notify.started()
String workRoot = (env.WORK_ROOT) ?: '$HOME/zanata-work-root'
currentBuild.displayName = currentBuild.displayName + " {${env.NODE_NAME}}"
// sh "gpg2 --clearsign <<<' '"
// Note that this checkout zanata-scripts
checkout scm
sh "$WORKSPACE/zanata-functions run checkout_branch zanata-platform release $workRoot"
String releaseVersion = params.RELEASE_VERSION
if (params.RELEASE_VERSION == 'auto') {
releaseVersion = sh(returnStdout: true,
script: "sed -r -n -e 's|^.*<version>([0-9.]*)(-SNAPSHOT)?</version>.*\$|\\1|p' $workRoot/zanata-platform/pom.xml",
)
}
echo "Release Version: $releaseVersion"
}
dir (workRoot . '/zanata-platform') {
stage('ReleaseNotes') {
String releaseNoteVersion = releaseVersion.replaceAll('-.*','')
echo "releaseNoteVersion: $releaseNoteVersion"
def releaseNoteStatus = sh(returnStatus: true,
script: "$WORKSPACE/zanata-release-notes-prepend -j $ARTIFACT_ID $releaseNoteVersion",
)
echo "releaseNoteStatus: $releaseNoteVersion"
switch(releaseNoteStatus){
case 0: // EXIT_OK
// ReleaseNotes updated. Git commit is done by zanata-release-notes-prepend
break
case 40: // EXIT_RETURN_FALSE
// ReleaseNotes does not changed
break
default:
error "Status($releaseNotStatus) Failed to get related jira issues"
break
}
}
stage('ReleaseTag') {
sh "printf\033[1;33m[Info] \033[0m Set release version to $releaseVersion"
sh "sed -i -e 's|<tag>HEAD</tag>|<tag>${ARTIFACT_ID}-${releaseVersion}</tag>|' \$(find . -name pom.xml | xargs )"
sh "./mvnw $MAVEN_EXTRA_OPTIONS $MAVEN_RELEASE_OPTIONS versions:set versions:set -DnewVersion=$releaseVersion"
sh "./mvnw scm:checkin -Dmessage='chore(version): set version $releaseVersion' -DpushChanges=false"
}
}
}
}