diff --git a/.pydevproject b/.pydevproject index d111c07..1ce5929 100644 --- a/.pydevproject +++ b/.pydevproject @@ -3,6 +3,6 @@ /${PROJECT_DIR_NAME} -python interpreter +python 2.7 python35 diff --git a/commandline/commandline.gsh b/commandline/commandline.gsh new file mode 100644 index 0000000..df99a75 --- /dev/null +++ b/commandline/commandline.gsh @@ -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 \ No newline at end of file diff --git a/configuration/configuration.gsh b/configuration/configuration.gsh new file mode 100644 index 0000000..29cd7e3 --- /dev/null +++ b/configuration/configuration.gsh @@ -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 diff --git a/versioncontrol/git.gsh b/versioncontrol/git.gsh new file mode 100644 index 0000000..70fe6bc --- /dev/null +++ b/versioncontrol/git.gsh @@ -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 \ No newline at end of file diff --git a/versionnumbering/versioninfo.py b/versionnumbering/versioninfo.py index 59b5225..9a7cd6a 100644 --- a/versionnumbering/versioninfo.py +++ b/versionnumbering/versioninfo.py @@ -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: