Move commonly used methods out to Common_scripts
This commit is contained in:
parent
c2458d0c82
commit
70b23d7049
3 changed files with 99 additions and 0 deletions
12
commandline/commandline.gsh
Normal file
12
commandline/commandline.gsh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
String getCommandOutput(String cmd) {
|
||||
if (isUnix()) {
|
||||
return sh(returnStdout: true, script: '#!/bin/sh -e\n' + cmd).trim()
|
||||
} else {
|
||||
return bat(returnStdout: true, script: """
|
||||
@echo off
|
||||
${cmd}
|
||||
"""
|
||||
).trim()
|
||||
}
|
||||
}
|
||||
|
||||
34
configuration/configuration.gsh
Normal file
34
configuration/configuration.gsh
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
def githelper = load("Common_scripts/versioncontrol/git.gsh")
|
||||
|
||||
configurationCollection = [:]
|
||||
|
||||
def registerConfigurationInfo(String configurationName, String configurationURL, String configurationVersion, String configurationSHA) {
|
||||
def ConfigurationInfo = [configurationURL, configurationVersion, configurationSHA]
|
||||
configurationCollection.put(configurationName, ConfigurationInfo)
|
||||
}
|
||||
|
||||
def registerPipelineScriptConfiguration() {
|
||||
registerConfigurationInfo('pipeline script', '-', '-', getGitInfo("${WORKSPACE}"))
|
||||
}
|
||||
|
||||
def saveConfigurationInVersionInfo() {
|
||||
dir("${WORKSPACE}\\version") {
|
||||
writeFile file: 'configuration.txt', text: getFormattedConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
String getFormattedConfiguration() {
|
||||
String formattedInfo = ""
|
||||
def keys = configurationCollection.keySet().sort()
|
||||
for (key in keys) {
|
||||
(configurationURL, configurationVersion, configurationSHA) = configurationCollection.get(key)
|
||||
formattedLine = String.format("%s:%s,%s,%s%n", key, configurationURL, configurationVersion, configurationSHA)
|
||||
formattedInfo += formattedLine
|
||||
}
|
||||
return formattedInfo
|
||||
}
|
||||
|
||||
def gitCheckoutAndRegister(String tool, String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
|
||||
githelper.gitCheckout(gitURL, revision, targetDir, repoRoot, cloneDepth, shallowClone)
|
||||
registerConfigurationInfo(tool, gitURL, revision, getGitInfo(targetDir))
|
||||
}
|
||||
53
versioncontrol/git.gsh
Normal file
53
versioncontrol/git.gsh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
def commandlinehelper = load("Common_scripts/commandline/commandline.gsh")
|
||||
|
||||
String getGitInfo(String workingSetRootPath) {
|
||||
dir(workingSetRootPath) {
|
||||
return commandlinehelper.getCommandOutput('git log -1 --format=oneline')
|
||||
}
|
||||
}
|
||||
|
||||
def gitCheckout(String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
userRemoteConfigs: [
|
||||
[url: gitURL]
|
||||
],
|
||||
branches: [
|
||||
[name: revision]
|
||||
],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [
|
||||
[$class: 'CleanBeforeCheckout'],
|
||||
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: "${REPO_ROOT}/${repoRoot}", shallow: shallowClone, timeout: 120],
|
||||
[$class: 'CheckoutOption', timeout: 60],
|
||||
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir]
|
||||
],
|
||||
submoduleCfg: [],
|
||||
])
|
||||
}
|
||||
|
||||
String getSHAFromVersion(String versionFolder) {
|
||||
dir (versionFolder) {
|
||||
srcRevision = readFile("gitrevision.txt").trim()
|
||||
}
|
||||
return srcRevision
|
||||
}
|
||||
|
||||
boolean checkAllVersionsAgree(java.util.LinkedHashMap versions) {
|
||||
def keys = versions.keySet()
|
||||
if (keys.size() <= 1) {
|
||||
return false
|
||||
} else {
|
||||
version = ""
|
||||
for (key in keys) {
|
||||
nextversion = versions.get(key)
|
||||
if (version == "") {
|
||||
version = nextversion
|
||||
}
|
||||
if (nextversion != version) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue