Skip to content

Commit 0f3d061

Browse files
committed
make getCheckoutInfo more reusable
1 parent 281de65 commit 0f3d061

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

vars/getCheckoutInfo.groovy

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
def call() {
22

33
def repoInfo = [
4-
branch: env.ghprbSourceBranch ?: params.branch_specifier ?: 'missing branch_specifier',
4+
branch: env.ghprbSourceBranch ?: params.branch_specifier ?: null,
55
targetBranch: env.ghprbTargetBranch,
66
]
77

8-
dir("kibana") {
9-
repoInfo.commit = sh(
10-
script: "git rev-parse HEAD",
11-
label: "determining checked out sha",
8+
repoInfo.commit = sh(
9+
script: "git rev-parse HEAD",
10+
label: "determining checked out sha",
11+
returnStdout: true
12+
).trim()
13+
14+
if (repoInfo.targetBranch) {
15+
sh(
16+
script: "git fetch origin ${repoInfo.targetBranch}",
17+
label: "fetch latest from '${repoInfo.targetBranch}' at origin"
18+
)
19+
repoInfo.mergeBase = sh(
20+
script: "git merge-base HEAD FETCH_HEAD",
21+
label: "determining merge point with '${repoInfo.targetBranch}' at origin",
1222
returnStdout: true
1323
).trim()
14-
15-
if (repoInfo.targetBranch) {
16-
sh(
17-
script: "git fetch https://github.com/elastic/kibana.git ${repoInfo.targetBranch}",
18-
label: "fetch latest from '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git"
19-
)
20-
repoInfo.mergeBase = sh(
21-
script: "git merge-base HEAD FETCH_HEAD",
22-
label: "determining merge point with '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git",
23-
returnStdout: true
24-
).trim()
25-
}
2624
}
2725

2826
print "repoInfo: ${repoInfo}"

vars/workers.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def base(Map params, Closure closure) {
5959
checkout scm
6060
}
6161

62-
checkoutInfo = getCheckoutInfo()
62+
def checkoutInfo
63+
dir("kibana") {
64+
checkoutInfo = getCheckoutInfo()
65+
}
66+
6367
ciStats.reportGitInfo(
6468
checkoutInfo.branch,
6569
checkoutInfo.commit,

0 commit comments

Comments
 (0)