This commit is contained in:
Dan Hawkins 2018-02-20 21:47:19 +00:00
commit 9867cf3da3
5 changed files with 132 additions and 8 deletions

View file

@ -3,6 +3,6 @@
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python35</pydev_property>
</pydev_project>

View file

@ -0,0 +1,13 @@
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()
}
}
return this

View file

@ -0,0 +1,36 @@
gh = load("${WORKSPACE}/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', '-', '-', gh.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) {
gh.gitCheckout(gitURL, revision, targetDir, repoRoot, cloneDepth, shallowClone)
registerConfigurationInfo(tool, gitURL, revision, gh.getGitInfo(targetDir))
}
return this

62
versioncontrol/git.gsh Normal file
View file

@ -0,0 +1,62 @@
clh = load("${WORKSPACE}/Common_scripts/commandline/commandline.gsh")
String getGitInfo(String workingSetRootPath) {
dir(workingSetRootPath) {
return clh.getCommandOutput('git log -1 --format=oneline')
}
}
def gitCheckout(String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
reporootenv = env.REPO_ROOT
if (reporootenv != null && repoRoot != "") {
reporootpath = "${reporootenv.trim()}/${repoRoot}"
} else {
reporootpath = ""
echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave"
}
checkout([
$class: 'GitSCM',
userRemoteConfigs: [
[url: gitURL]
],
branches: [
[name: revision]
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'CleanBeforeCheckout'],
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: reporootpath, 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
}
return this

View file

@ -65,10 +65,14 @@ def getGitRevision(gitrootpath, basenumber):
return (adjustedchangecount, revision, remoteinfo)
# Handle:
# origin/master
# origin/2.0.x
def getVersionPrefix(sourcebranch):
print("Determining version number prefix from source branch name: {0}".format(sourcebranch))
defaultversionprefix = "1.30000.0."
mastertypeversionprefix = "1.20000.0."
splits = sourcebranch.split('/')
if len(splits) < 1:
print("Source branch name is invalid. Defaulting to: {0}".format(defaultversionprefix))
@ -77,7 +81,7 @@ def getVersionPrefix(sourcebranch):
sourcebranch = splits[-1]
if sourcebranch.lower().endswith("master"): # Special case
return "1.20000.0."
return mastertypeversionprefix
splits = sourcebranch.split('.')
versionprefix = ""
@ -86,26 +90,32 @@ def getVersionPrefix(sourcebranch):
versionprefix = defaultversionprefix
else:
splitnumbercount = 0
isIntermediateReleaseBranch = False
for split in splits:
if split.isdigit():
versionprefix += split + "."
splitnumbercount += 1
else:
if split == "x":
isIntermediateReleaseBranch = True
break
if splitnumbercount > 2:
break
if splitnumbercount == 0:
print("No leading numbers were found in source branch name so defaulting to: {0}".format(defaultversionprefix))
versionprefix = defaultversionprefix
elif splitnumbercount == 1:
versionprefix += "0.0."
elif splitnumbercount == 2:
versionprefix += "0."
else:
if isIntermediateReleaseBranch:
versionprefix = mastertypeversionprefix
elif splitnumbercount == 1:
versionprefix += "0.0."
elif splitnumbercount == 2:
versionprefix += "0."
print("Determined version prefix to be: {0}".format(versionprefix))
return versionprefix
def writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevision, remoteinfo, buildnumber, buildstamp):
def writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevisioncount, gitrevision, remoteinfo, buildnumber, buildstamp):
with open(os.path.join(versionfolder, "buildjobname.txt"), 'w') as f:
f.write(buildjobname)
@ -113,6 +123,9 @@ def writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevision, r
f.write(versionprefix)
with open(os.path.join(versionfolder, "revision.txt"), 'w') as f:
f.write(str(gitrevisioncount))
with open(os.path.join(versionfolder, "gitrevision.txt"), 'w') as f:
f.write(gitrevision)
with open(os.path.join(versionfolder, "remoteinfo.txt"), 'w') as f:
@ -185,7 +198,7 @@ USAGE
buildstamp = versionprefix + str(gitrevisioncount)
print("Build stamp is: {0}".format(buildstamp))
writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevision, remoteinfo, buildnumber, buildstamp)
writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevisioncount, gitrevision, remoteinfo, buildnumber, buildstamp)
return 0
except Exception as e: