Skip to content

Commit 4146d6d

Browse files
committed
Merge branch 'ProjectName' into 'master'
Jenkinsfile#projectNamePattern added See merge request exedio/cops!43
2 parents bafc83c + ab000e7 commit 4146d6d

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

Jenkinsfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!'groovy'
2+
import groovy.transform.Field
23

3-
def projectName = env.JOB_NAME.substring(0, env.JOB_NAME.indexOf("/")) // depends on name and location of multibranch pipeline in jenkins
4+
@Field
5+
String projectNamePattern = "^exedio/([a-z]*)/.*" // depends on location of multibranch pipeline in jenkins
46
def jdk = 'openjdk-17'
57
def idea = '2021.2'
68
def ideaSHA256 = '7c27799861fb1ba0d43a3565a1ec2be789e1871191be709f0e79f1e17d3571fe'
@@ -142,7 +144,7 @@ try
142144

143145
parallelBranches["Ivy"] =
144146
{
145-
def cache = 'jenkins-build-survivor-' + projectName + "-Ivy"
147+
def cache = 'jenkins-build-survivor-' + projectName() + "-Ivy"
146148
//noinspection GroovyAssignabilityCheck
147149
lockNodeCheckoutAndDelete(cache)
148150
{
@@ -190,6 +192,22 @@ finally
190192
updateGitlabCommitStatus state: currentBuild.resultIsBetterOrEqualTo("SUCCESS") ? "success" : "failed" // https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
191193
}
192194

195+
// ------------------- LIBRARY ----------------------------
196+
// The code below is meant to be equal across all projects.
197+
198+
String projectName()
199+
{
200+
String jobName = env.JOB_NAME
201+
java.util.regex.Matcher m = java.util.regex.Pattern.compile(projectNamePattern).
202+
matcher(jobName)
203+
if(!m.matches())
204+
error "illegal jobName >" + jobName + "<, must match " + projectNamePattern
205+
206+
String result = m.group(1)
207+
echo("project name >" + result + "< computed from >" + jobName + "<")
208+
return result
209+
}
210+
193211
def lockNodeCheckoutAndDelete(resource, Closure body)
194212
{
195213
lock(resource)

0 commit comments

Comments
 (0)