Skip to content

Commit

Permalink
use dir() rather than cd in every script
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 18, 2020
1 parent dde253d commit d9d3575
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions vars/getCheckoutInfo.groovy
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
def call(scmVars) {
def branch = env.ghprbSourceBranch ?: scmVars.GIT_LOCAL_BRANCH ?: scmVars.GIT_BRANCH
def repoInfo = [:]

def commit = sh(
script: "cd kibana && git rev-parse HEAD",
label: "determining checked out sha",
returnStdout: true
).trim()
repoInfo.branch = env.ghprbSourceBranch ?: scmVars.GIT_LOCAL_BRANCH ?: scmVars.GIT_BRANCH
repoInfo.targetBranch = env.ghprbTargetBranch

def targetBranch = env.ghprbTargetBranch
def mergeBase
if (env.ghprbTargetBranch) {
sh(
script: "cd kibana && git fetch https://github.com/elastic/kibana.git ${env.ghprbTargetBranch}",
label: "fetch latest from '${env.ghprbTargetBranch}' at https://github.com/elastic/kibana.git"
)
mergeBase = sh(
script: "cd kibana && git merge-base HEAD FETCH_HEAD",
label: "determining merge point with '${env.ghprbTargetBranch}' at https://github.com/elastic/kibana.git",
dir("kibana") {
repoInfo.commit = sh(
script: "git rev-parse HEAD",
label: "determining checked out sha",
returnStdout: true
).trim()
}

def repoInfo = [
commit: commit,
branch: branch,
targetBranch: targetBranch,
mergeBase: mergeBase,
]
if (repoInfo.targetBranch) {
sh(
script: "git fetch https://github.com/elastic/kibana.git ${repoInfo.targetBranch}",
label: "fetch latest from '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git"
)
repoInfo.mergeBase = sh(
script: "git merge-base HEAD FETCH_HEAD",
label: "determining merge point with '${repoInfo.targetBranch}' at https://github.com/elastic/kibana.git",
returnStdout: true
).trim()
}
}

print "repoInfo: ${repoInfo}"

Expand Down

0 comments on commit d9d3575

Please sign in to comment.