-
Notifications
You must be signed in to change notification settings - Fork 124
/
Jenkinsfile-master-release
65 lines (51 loc) · 2.68 KB
/
Jenkinsfile-master-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
#!/usr/bin/env groovy
def releaseBranch
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 scm
}
stage('Branch') {
// Drop -SNAPSHOT qualifier
sh 'mvn versions:set -DremoveSnapshot versions:commit'
// Save release version
def pom = readMavenPom file: 'pom.xml'
releaseVersion = pom.version
echo "Set release version to ${releaseVersion}"
// Verify if branch exists
def versionTokens = releaseVersion.split('\\.')
releaseBranch = "stable-${versionTokens[0]}-${versionTokens[1]}"
echo "Release branch name is ${releaseBranch}"
withCredentials([usernamePassword(credentialsId: 'CXSGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
env.RELEASE_BRANCH = releaseBranch
def branchExists = sh(script: 'git ls-remote --heads https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com:RestComm/media-core.git $RELEASE_BRANCH | wc -l', returnStdout: true)
if (branchExists == 1) {
echo "Branch ${releaseBranch} already exists. Aborting job."
currentBuild.result = 'FAILURE'
return
} else {
echo "Branch ${releaseBranch} does not exist. Proceeding to next stage."
}
// Create stable branch
sh "git checkout -b ${releaseBranch}"
sh "git commit -a -m \"New stable release ${releaseVersion}\""
env.RELEASE_BRANCH = "${releaseBranch}"
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/RestComm/media-core.git ${RELEASE_BRANCH}')
}
}
stage('Release') {
// Tag code
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 -Dgpg.passphrase=${env.GPG_PASSPHRASE} -Pattach-sources,generate-javadoc,release-sign-artifacts,cxs-oss-release"
}
}