forked from apache/incubator-kie-kogito-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.release.create-branches
88 lines (73 loc) · 2.45 KB
/
Jenkinsfile.release.create-branches
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
@Library('jenkins-pipeline-shared-libraries')_
pipeline {
agent {
label 'kie-rhel7 && !master'
}
options {
timeout(time: 120, unit: 'MINUTES')
}
// parameters {
// For parameters, check into .jenkins/dsl/jobs.groovy file
// }
// environment {
// Some generated env is also defined into .jenkins/dsl/jobs.groovy file
// }
stages {
stage('Initialize') {
steps {
script {
echo 'Initialize'
assert getReleaseBranch() != ''
currentBuild.displayName = "${getReleaseBranch()}"
currentBuild.description = "${getRepositories()}"
}
}
}
stage('Create release branches') {
steps {
script {
echo 'Create release branches'
for (String repo : getRepositories()) {
echo "Checkout repo ${repo}"
dir(repo) {
deleteDir()
checkout(githubscm.resolveRepository(getUrl(repo), getGitAuthor(), getBase(repo), false))
sh 'git fetch origin'
String branchRemoteResult = sh(script: "git ls-remote origin ${getReleaseBranch()} | wc -l", returnStdout: true).trim()
if (Integer.parseInt(branchRemoteResult) > 0) {
echo 'Release branch already exist ... will not create it'
} else {
echo "Release branch ${getReleaseBranch()} does not exist ... gonna create it"
githubscm.createBranch(getReleaseBranch())
githubscm.pushObject('origin', getReleaseBranch(), getGitAuthorCredsId())
}
}
}
}
}
}
}
post {
always {
cleanWs()
}
}
}
String getReleaseBranch() {
return params.RELEASE_BRANCH
}
String getGitAuthor() {
return env.GIT_AUTHOR
}
String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDS_ID
}
String[] getRepositories() {
return params.REPOSITORIES.split(',')
}
String getUrl(String repo) {
return repo.split(':')[0]
}
String getBase(String repo) {
return (repo.find(':')) ? repo.split(':')[1] : env.DEFAULT_BASE_BRANCH
}