-
Notifications
You must be signed in to change notification settings - Fork 124
/
Jenkinsfile-stable-integration-release
119 lines (92 loc) · 4.39 KB
/
Jenkinsfile-stable-integration-release
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
#!/usr/bin/env groovy
def branchBase
def commitAuthor
def commitMsg
def releaseVersion
node("cxs-slave-master") {
configFileProvider([configFile(fileId: '37cb206e-6498-4d8a-9b3d-379cd0ccd99b', targetLocation: 'settings.xml')]) {
sh 'mkdir -p ~/.m2 && sed -i "s|@LOCAL_REPO_PATH@|$WORKSPACE/M2_REPO|g" $WORKSPACE/settings.xml && cp $WORKSPACE/settings.xml -f ~/.m2/settings.xml'
}
stage('Checkout') {
// Checkout PR
checkout scm
// Find base branch
def remoteBranches = sh(script: 'git branch -r', returnStdout: true)
branchBase = remoteBranches.split('\n')[1].split('/')[1].trim()
echo "Target branch is ${branchBase}"
// Find contributor
commitAuthor = sh(script: 'git log -1 HEAD~2 --pretty=format:\'%an <%ae>\'', returnStdout: true).trim()
echo "Author is ${commitAuthor}"
}
stage('Build') {
sh "mvn clean install -DskipTests"
}
stage('Test') {
sh 'mvn test'
junit testResults: '**/target/surefire-reports/*.xml', testDataPublishers: [[$class: 'StabilityTestDataPublisher']]
}
}
stage('UserApproval') {
agent none
steps {
script {
timeout(time:5, unit:'DAYS') {
def userInput = input message: 'Waiting for maintainer review', parameters:
[text(name: 'commitMsg', defaultValue: '', description: 'Commit Message')]
commitMsg = userInput['commitMsg']
}
}
milestone 1
}
}
node("cxs-slave-master") {
configFileProvider([configFile(fileId: '37cb206e-6498-4d8a-9b3d-379cd0ccd99b', targetLocation: 'settings.xml')]) {
sh 'mkdir -p ~/.m2 && sed -i "s|@LOCAL_REPO_PATH@|$WORKSPACE/M2_REPO|g" $WORKSPACE/settings.xml && cp $WORKSPACE/settings.xml -f ~/.m2/settings.xml'
}
lock("media-core-${branchBase}") {
stage('Versioning') {
// Checkout PR
checkout scm
// Create local branch
sh 'git branch local_branch && git checkout local_branch'
// Increment project version. Only patches are allowed in stable branches
sh 'mvn build-helper:parse-version versions:set -DnewVersion=\\${parsedVersion.majorVersion}.\\${parsedVersion.minorVersion}.\\${parsedVersion.nextIncrementalVersion} versions:commit'
// Save project version
def pom = readMavenPom file: 'pom.xml'
releaseVersion = pom.version
echo "Updated project version to ${releaseVersion}"
sh 'git add -u'
sh "git commit -m \"Updated project version to ${releaseVersion}\""
}
stage('Integration') {
// Merge feature to base branch
sh "git checkout ${branchBase}"
sh 'git merge --squash local_branch'
sh "git commit -a --author=\"${commitAuthor}\" --message=\"${commitMsg}\""
def gitLog = sh(script: 'git log -1 --pretty=full', returnStdout: true)
echo "${gitLog}"
// Push Changes to base branch
withCredentials([usernamePassword(credentialsId: 'CXSGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
// Push changes to base branch
env.BASE_BRANCH = "${branchBase}"
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/RestComm/media-core.git $BASE_BRANCH')
}
// Delete local branch
sh 'git branch -D local_branch'
// Invalidate older builds forcing re-scan of PR
// Aims to maintain master healthy and prevent that one PR tramples another
milestone 2
}
}
stage('Delivery') {
// Tag release
withCredentials([usernamePassword(credentialsId: 'CXSGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag ${releaseVersion}"
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/RestComm/media-core.git --tags')
}
// Deploy to CXS Nexus
sh 'mvn package deploy:deploy -Pattach-sources,generate-javadoc,maven-release -DskipTests -DskipNexusStagingDeployMojo -DaltDeploymentRepository=nexus::default::$CXS_NEXUS2_URL'
// Release to Sonatype
sh "mvn clean deploy -DskipTests=true -Dgpg.passphrase=${env.GPG_PASSPHRASE} -Pattach-sources,generate-javadoc,release-sign-artifacts,cxs-oss-release"
}
}