Merge remote-tracking branch 'remotes/origin/master' into production
# Conflicts: # Common_scripts/install/installhelper.gsh # compile/compile.gsh
This commit is contained in:
commit
6638b52c9d
29 changed files with 1908 additions and 453 deletions
23
artifacts/metaexport.groovy
Normal file
23
artifacts/metaexport.groovy
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
// Take a list of Sub-job descriptors and output folder pairs, copy the artifacts, while filling in a string of artifact folders
|
||||
def combineSubjobArtifacts(meta, subJobs) {
|
||||
def importer = load("${autobuilder.commonscripts()}/import/importer.groovy")
|
||||
|
||||
def ArrayList<String> artifactFolders = new ArrayList<String>()
|
||||
for (subJob in subJobs) {
|
||||
def subJobObject = subJob[0]
|
||||
if (subJobObject != null) {
|
||||
def subJobName = subJobObject.getProjectName()
|
||||
def subJobNumber = subJobObject.getNumber()
|
||||
destFolder = subJob[1]
|
||||
dir(destFolder) {
|
||||
deleteDir()
|
||||
}
|
||||
importer.artifactimport(meta, subJobName, subJobNumber, destFolder)
|
||||
artifactFolders.add("${destFolder}/**")
|
||||
}
|
||||
}
|
||||
return artifactFolders
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
// Take a list of Sub-job descriptors and output folder pairs, copy the artifacts, while filling in a string of artifact folders
|
||||
def combineSubjobArtifacts(subJobs) {
|
||||
artifactFolders = ""
|
||||
for (subJob in subJobs) {
|
||||
subJobObject = subJob[0]
|
||||
artifactFolder = subJob[1]
|
||||
if (subJobObject != null) {
|
||||
subJobName = subJobObject.getProjectName()
|
||||
subJobNumber = subJobObject.getNumber()
|
||||
destFolder = "${artifactFolder}"
|
||||
|
||||
dir("${destFolder}") {
|
||||
deleteDir()
|
||||
}
|
||||
|
||||
echo "Copying artifacts from: Job: ${subJobName} Number: ${subJobNumber} to folder: ${destFolder}"
|
||||
copyArtifacts fingerprintArtifacts: true, projectName: "${subJobName}", selector: specific("${subJobNumber}"), target: "${destFolder}"
|
||||
artifactFolders += "${destFolder}/**,"
|
||||
}
|
||||
}
|
||||
return artifactFolders;
|
||||
}
|
||||
|
||||
return this;
|
||||
66
autobuilder.groovy
Normal file
66
autobuilder.groovy
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// Assume that WORKSPACE environment variable is set
|
||||
|
||||
autobuildroot = "${WORKSPACE}/autobuild"
|
||||
|
||||
commonscriptsroot = "${autobuildroot}/Common_scripts"
|
||||
|
||||
metafolderscript = null
|
||||
|
||||
def conditionalclean(doclean = "${CLEAN_WORKSPACE}" == "true") {
|
||||
if (doclean) {
|
||||
echo "Cleaning workspace"
|
||||
// Save any script files that were loaded into the workspace at first and are required after cleaning the workspace
|
||||
stash allowEmpty: true, includes: 'autobuild/**', name: 'Clean workspace stash', useDefaultExcludes: false
|
||||
cleanWs()
|
||||
unstash name: 'Clean workspace stash'
|
||||
}
|
||||
else {
|
||||
echo "Not cleaning workspace"
|
||||
}
|
||||
}
|
||||
|
||||
def commonscripts() {
|
||||
return commonscriptsroot
|
||||
}
|
||||
|
||||
def getautobuildpath() {
|
||||
return autobuildroot
|
||||
}
|
||||
|
||||
def getmetafolderscript() {
|
||||
return metafolderscript
|
||||
}
|
||||
|
||||
// Start up boilderplate
|
||||
def start(script, productname = PRODUCT_NAME, subcomponentname = SUBCOMPONENT_NAME, jirakey = JIRA_KEY, releaserepo = RELEASE_REPO, autobuildpath = autobuildroot, commonscriptspath = commonscriptsroot) {
|
||||
echo "Starting...."
|
||||
|
||||
autobuildroot = autobuildpath
|
||||
commonscriptsroot = commonscriptspath
|
||||
metafolderscript = load("${commonscripts()}/meta/folder.groovy")
|
||||
|
||||
conditionalclean()
|
||||
|
||||
def meta = getmetafolderscript().metareset(script)
|
||||
meta.productinfo.set(productname, subcomponentname, jirakey)
|
||||
def now = new Date()
|
||||
now.format("yyMMdd.HHmm", TimeZone.getTimeZone('UTC'))
|
||||
meta.jenkinsbuildinfo.set(JOB_NAME, BUILD_ID.toInteger(), NODE_NAME, now.toString())
|
||||
|
||||
def rr = load("${commonscripts()}/release/registerrepo.groovy")
|
||||
rr.registerrepo(meta, releaserepo)
|
||||
|
||||
def ch = load("${commonscripts()}/configuration/configuration.groovy")
|
||||
ch.registerPipelineScriptConfiguration(meta)
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
def configurationhelper() {
|
||||
return load("${commonscripts()}/configuration/configuration.groovy")
|
||||
}
|
||||
|
||||
// Everyone wants to know this
|
||||
autobuilder = this
|
||||
|
||||
return this;
|
||||
14
checksum/utils.groovy
Normal file
14
checksum/utils.groovy
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
// Generate a checksum file of from a list of files/directories relative to workspace
|
||||
def generatelist(meta, checksummable) {
|
||||
for (filepath in checksummable) {
|
||||
def checksumset = meta.checksuminfo.addChecksumSet(filepath)
|
||||
def files = findFiles(glob: filepath)
|
||||
for (file in files) {
|
||||
def sum = sha1(file: file.path).trim()
|
||||
checksumset.addChecksumPair(file.path, sum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
10
clean/clean.groovy
Normal file
10
clean/clean.groovy
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
def clean(folderlist) {
|
||||
for (folder in folderlist) {
|
||||
dir(folder) {
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -117,7 +117,14 @@ def doImportProjects(ds5folder, toolchainfolder, ds5shellcommand, buildcommand,
|
|||
}
|
||||
|
||||
// Build and export files
|
||||
def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder, exportfolder = "${WORKSPACE}/bin") {
|
||||
def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sourcefolder, variantstobuild, exportfolder = "${WORKSPACE}/bin") {
|
||||
toBuild = []
|
||||
if (variantstobuild) {
|
||||
toBuildUntrimmed = variantstobuild.split(',')
|
||||
toBuildUntrimmed.each {
|
||||
toBuild.add(it.trim())
|
||||
}
|
||||
}
|
||||
// The lock is being used because it was being found that the doKillLeftovers was affecting other builds
|
||||
lock(resource: "eclipsebuild_${env.NODE_NAME}") {
|
||||
try {
|
||||
|
|
@ -137,26 +144,31 @@ def doBuild(apps, ds5folder, toolchainfolder, ds5shellcommand, buildcommand, sou
|
|||
for (build_variant in variants) {
|
||||
retry(maxprojectbuildretries) { // Eclipse occasionally raises exceptions (rather than the builds failing)
|
||||
try {
|
||||
doDisplayLeftovers()
|
||||
doRegisterToolchain(ds5folder, toolchainfolder)
|
||||
echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'"
|
||||
timeout(time: 10, unit: 'MINUTES') {
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
echo Start time: `date`
|
||||
${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'
|
||||
echo End time: `date`
|
||||
"""
|
||||
if (toBuild.contains(build_variant)) {
|
||||
doDisplayLeftovers()
|
||||
doRegisterToolchain(ds5folder, toolchainfolder)
|
||||
echo "Build command: ${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'"
|
||||
timeout(time: 10, unit: 'MINUTES') {
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
echo Start time: `date`
|
||||
${ds5shellcommand} \'${buildcommand} -no-indexer ${buildtype} \"${project}/${build_variant}\"\'
|
||||
echo End time: `date`
|
||||
"""
|
||||
}
|
||||
else {
|
||||
bat """
|
||||
"%ds5shellcommand%" "%buildcommand%" -no-indexer ${buildtype} "${project}\\${build_variant}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
else {
|
||||
bat """
|
||||
"%ds5shellcommand%" "%buildcommand%" -no-indexer ${buildtype} "${project}\\${build_variant}"
|
||||
"""
|
||||
result = doExport(exportfolder, exportpathlist, "", build_variant)
|
||||
if (result != 0) {
|
||||
error "Failed to copy...."
|
||||
}
|
||||
}
|
||||
result = doExport(exportfolder, exportpathlist, "", build_variant)
|
||||
if (result != 0) {
|
||||
error "Failed to copy...."
|
||||
else {
|
||||
echo "Not building ${build_variant} variant of project: ${project}"
|
||||
}
|
||||
} catch (Exception e) {
|
||||
echo "Build failed - Waiting for a while"
|
||||
116
compile/eclipsebuild/eclipseniosbuild.groovy
Normal file
116
compile/eclipsebuild/eclipseniosbuild.groovy
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// Gets the debug and optimization flags.
|
||||
// Arg1 is "app" or "lib". Returns flags.
|
||||
// Restore the debug and optimization levels, in case this is a dev machine.
|
||||
// Arg1 is "app" or "lib". Arg2-3 is flags from getFlags. Returns nothing.
|
||||
def setFlagsToRelease(NIOSEDS, project, wdir) {
|
||||
if ( project == "app" ) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
cd "${wdir}"
|
||||
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-app-update-makefile --app-dir=. --set-optimization=-O2 --set-debug-level=
|
||||
"""
|
||||
}
|
||||
}
|
||||
else if ( project == "lib" ) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
cd "${wdir}"
|
||||
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-lib-update-makefile --lib-dir=. --set-optimization=-O2 --set-debug-level=
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def remake_and_check(NIOSEDS, wdir) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
cd "${wdir}"
|
||||
|
||||
# Use the makefile to clean and build
|
||||
"${NIOSEDS}/nios2_command_shell.sh" make clean
|
||||
if [ \$? -ne 0 ]; then exit 1; fi
|
||||
|
||||
# Set the debug and optimization levels to production values
|
||||
"${NIOSEDS}/nios2_command_shell.sh" make -j12 all
|
||||
if [ \$? -ne 0 ]; then exit 1; fi
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
def generate_bsp(NIOSEDS, bspfolder) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-bsp-generate-files --bsp-dir "${bspfolder}" --log "${bspfolder}/bsp.log" --settings "${bspfolder}/settings.bsp"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
def modifylib(NIOSEDS, bspfolder, buildconfig, wdir) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
|
||||
cd "${wdir}"
|
||||
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-lib-update-makefile --lib-dir=. --set-bsp-dir "${bspfolder}" --set-active-build-config "${buildconfig}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
def modifyapp(NIOSEDS, bspfolder, wdir) {
|
||||
if (isUnix()) {
|
||||
sh """#!/bin/bash
|
||||
set -x
|
||||
|
||||
cd "${wdir}"
|
||||
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-app-update-makefile --app-dir=. --set-bsp-dir "${bspfolder}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
def dump_elf_info(NIOSEDS, elffile, meta, custominfokeyprefix) {
|
||||
if (isUnix()) {
|
||||
def cpu_name = sh(script: """#!/bin/bash
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-elf-query "${elffile}" --cpu_name
|
||||
""",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
meta.addCustomInfo("${custominfokeyprefix}_cpu_name", cpu_name)
|
||||
def sidp = sh(script: """#!/bin/bash
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-elf-query "${elffile}" --sidp
|
||||
""",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
meta.addCustomInfo("${custominfokeyprefix}_sidp", sidp)
|
||||
def id = sh(script: """#!/bin/bash
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-elf-query "${elffile}" --id
|
||||
""",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
meta.addCustomInfo("${custominfokeyprefix}_id", id)
|
||||
def timestamp = sh(script: """#!/bin/bash
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-elf-query "${elffile}" --timestamp
|
||||
""",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
meta.addCustomInfo("${custominfokeyprefix}_timestamp", timestamp)
|
||||
/*
|
||||
def sopcinfo = sh(script: """#!/bin/bash
|
||||
"${NIOSEDS}/nios2_command_shell.sh" nios2-elf-query "${elffile}" --sopcinfo
|
||||
""",
|
||||
returnStdout: true
|
||||
).trim()
|
||||
meta.addCustomInfo("${custominfokeyprefix}_sopcinfo", sopcinfo)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
16
configuration/configuration.groovy
Normal file
16
configuration/configuration.groovy
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
|
||||
|
||||
def registerConfigurationInfo(meta, String configurationName, String configurationURL, String configurationVersion, String configurationSHA) {
|
||||
meta.addConfigurationInfo(configurationName, configurationURL, configurationVersion, configurationSHA)
|
||||
}
|
||||
|
||||
def registerPipelineScriptConfiguration(meta) {
|
||||
registerConfigurationInfo(meta, 'pipeline script', '-', '-', gh.getGitInfo("${autobuilder.getautobuildpath()}"))
|
||||
}
|
||||
|
||||
def gitCheckoutAndRegister(meta, 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(meta, tool, gitURL, revision, gh.getGitInfo(targetDir))
|
||||
}
|
||||
|
||||
return this
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
gh = 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', '-', '-', gh.getGitInfo("${AUTOBUILD_SCRIPTS}"))
|
||||
}
|
||||
|
||||
def saveConfigurationInVersionInfo() {
|
||||
dir("${WORKSPACE}/version") {
|
||||
echo "Writing configuration info to ${WORKSPACE}/version/configuration.txt"
|
||||
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
|
||||
18
differences/do.groovy
Normal file
18
differences/do.groovy
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
def differences(meta, String sourcerevision, String previoussourcerevision, String sourcepath) {
|
||||
def String cs = autobuilder.commonscripts()
|
||||
def String difffile = meta.difffilepath()
|
||||
def String jirakey = meta.productinfo.jirakey
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
"${PYTHON}" -u "${cs}/differences/show_release_differences.py" -g "${sourcepath}" -s "${sourcerevision}" -p "${previoussourcerevision}" -j "${jirakey}" -o "opposite notcommon" -f "${difffile}"
|
||||
"""
|
||||
}
|
||||
else {
|
||||
bat """
|
||||
"${PYTHON}" -u "${cs}\\differences\\show_release_differences.py" -g "${sourcepath}" -s "${sourcerevision}" -p "${previoussourcerevision}" -j "${jirakey}" -o "opposite notcommon" -f "${difffile}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -29,10 +29,6 @@ class GitException(Exception):
|
|||
def __repr__(self):
|
||||
return self.message
|
||||
|
||||
def makeFolder(versionfolder):
|
||||
print("Creating folder (if not already there): {0}".format(versionfolder))
|
||||
os.makedirs(versionfolder, exist_ok = True)
|
||||
|
||||
def printDivider(outfh, times = 1, length = 100):
|
||||
for _ in range(times):
|
||||
outfh.write("{0}\n".format("*" * length))
|
||||
|
|
@ -84,6 +80,9 @@ jiraprojectpattern = {
|
|||
'HMBFDHV': ( re.compile("^.* +(?:[Hh][Mm][Bb][Ff][Dd][Hh][Vv][ _-]*|\#\s*)(\d+):*(.*)$"),
|
||||
re.compile('^(\S*) Revert " *HMBFDHV-(\d+):* (.*)"$'),
|
||||
),
|
||||
'HMBFDGMA': ( re.compile("^.* +(?:[Hh][Mm][Bb][Ff][Dd][Gg][Mm][Aa][ _-]*|\#\s*)(\d+):*(.*)$"),
|
||||
re.compile('^(\S*) Revert " *HMBFDGMA-(\d+):* (.*)"$'),
|
||||
),
|
||||
}
|
||||
|
||||
mergepattern = re.compile("^(.*)((?:Merge branch '.*'|Merge remote-tracking branch '.*'|Merge commit '.*'|Add '.*' from commit).*)$")
|
||||
|
|
@ -172,7 +171,7 @@ USAGE
|
|||
parser.add_argument("-p", "--previousversion", dest="previousversion", action="store", default="origin/master", help="source branch or tag to compare with [default: %(default)s]")
|
||||
parser.add_argument("-j", "--jirakeyprefix", dest="jirakeyprefix", action="store", default="GIS", help="jira key prefix [default: %(default)s]")
|
||||
parser.add_argument("-o", "--outputoptions", dest="outputoptions", action="store", default="", help="output options: Can be: opposite notcommon [default: %(default)s]")
|
||||
parser.add_argument("-v", "--versionfolder", dest="versionfolder", action="store", default="", help="version folder where differences file stored [default: %(default)s]")
|
||||
parser.add_argument("-f", "--difffile", dest="difffile", action="store", default="", help="file where differences file stored [default: %(default)s]")
|
||||
|
||||
# Process arguments
|
||||
args = parser.parse_args()
|
||||
|
|
@ -183,14 +182,14 @@ USAGE
|
|||
previousversion = args.previousversion
|
||||
jirakeyprefix = args.jirakeyprefix
|
||||
outputoptions = args.outputoptions
|
||||
versionfolder = args.versionfolder
|
||||
difffile = args.difffile
|
||||
|
||||
print("Git root:", gitrootfolder, "Source version:", sourceversion, "Previous source version:", previousversion)
|
||||
print("Jira key prefix:", jirakeyprefix, "Output options:", outputoptions, "Version folder:", versionfolder)
|
||||
print("Jira key prefix:", jirakeyprefix, "Output options:", outputoptions, "Diff file:", difffile)
|
||||
|
||||
if versionfolder:
|
||||
makeFolder(versionfolder)
|
||||
outfh = open(os.path.join(versionfolder, "differences.txt"), 'w')
|
||||
if difffile:
|
||||
os.makedirs(os.path.dirname(difffile), exist_ok=True)
|
||||
outfh = open(difffile, 'w')
|
||||
else:
|
||||
outfh = sys.stdout
|
||||
|
||||
|
|
@ -209,7 +208,7 @@ USAGE
|
|||
gitlog = getGitLogDifferences(outfh, gitrootfolder, sourceversion, previousversion, tripledot = True)
|
||||
showDifferences(processLog(gitlog, jirakeyprefix), jirakeyprefix, outfh)
|
||||
|
||||
if versionfolder:
|
||||
if difffile:
|
||||
outfh.close()
|
||||
return 0
|
||||
except Exception as e:
|
||||
|
|
|
|||
34
import/importer.groovy
Normal file
34
import/importer.groovy
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
versiongenerator = load("${autobuilder.commonscripts()}/versionnumbering/generate.groovy")
|
||||
|
||||
def artifactimport(meta, String jenkinsjob, int buildnumber, String destpath, String filter = '**', String excludes = '', boolean fingerprint = false) {
|
||||
copyArtifacts(
|
||||
filter: filter,
|
||||
excludes: excludes,
|
||||
fingerprintArtifacts: fingerprint,
|
||||
projectName: jenkinsjob.trim(),
|
||||
selector: specific(buildnumber.toString()),
|
||||
target: destpath
|
||||
)
|
||||
def importedmeta = meta.importrelated(destpath)
|
||||
meta.buildstampinfo.changerevision(versiongenerator.incrementrevision(meta.buildstampinfo.revision, importedmeta.buildstampinfo.revision))
|
||||
return importedmeta
|
||||
}
|
||||
|
||||
def artifactimport(meta, String jenkinsjob, String buildselector, String destpath, String filter = '**', String excludes = '', boolean fingerprint = false) {
|
||||
copyArtifacts(
|
||||
filter: filter,
|
||||
excludes: excludes,
|
||||
fingerprintArtifacts: fingerprint,
|
||||
projectName: jenkinsjob.trim(),
|
||||
selector: [
|
||||
$class: 'ParameterizedBuildSelector',
|
||||
parameterName: buildselector
|
||||
],
|
||||
target: destpath
|
||||
)
|
||||
def importedmeta = meta.importrelated(destpath)
|
||||
meta.buildstampinfo.changerevision(versiongenerator.incrementrevision(meta.buildstampinfo.revision, importedmeta.buildstampinfo.revision))
|
||||
return importedmeta
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -1,29 +1,21 @@
|
|||
// Given details about artifacts to import and details of installers to build, import artifacts that are required
|
||||
def artifactsImporter(artifactDetails, installerDetails) {
|
||||
def Map artifactsImporter(meta, artifactDetails, installerDetails) {
|
||||
artifactFetched = [:]
|
||||
|
||||
def importer = load("${autobuilder.commonscripts()}/import/importer.groovy")
|
||||
for (installer in toBuild) {
|
||||
def artifactKey = installerDetails.get(installer)[0]
|
||||
//echo "To build: ${installer} use artifactKey: ${artifactKey}"
|
||||
(sourceProject, destFolder, toCopy, notToCopy, binariesFolders) = artifactDetails.get(artifactKey)
|
||||
env.importDest = destFolder
|
||||
(sourceProject, sourceselector, destFolder, toCopy, notToCopy, binariesFolders) = artifactDetails.get(artifactKey)
|
||||
if (artifactFetched.get(artifactKey) == null) {
|
||||
//echo "Artifact info: ${artifactInfo}"
|
||||
copyArtifacts excludes: notToCopy, filter: toCopy, fingerprintArtifacts: false, projectName: "${sourceProject}", selector: lastSuccessful(), target: "${destFolder}"
|
||||
def componentVersionFolder = "${WORKSPACE}\\version\\version_${artifactKey}"
|
||||
def folderToCopy = "${destFolder}\\version"
|
||||
echo "Copying from: ${folderToCopy} to: ${componentVersionFolder}"
|
||||
fileOperations([folderCopyOperation(destinationFolderPath: componentVersionFolder, sourceFolderPath: folderToCopy)])
|
||||
//fileOperations([fileCopyOperation(excludes: '', flattenFiles: false, includes: filesToCopy, targetLocation: componentVersionFolder )])
|
||||
artifactVersion = githelper.getSHAFromVersion("${destFolder}/version")
|
||||
artifactFetched.put(artifactKey, artifactVersion)
|
||||
def importmeta = importer.artifactimport(meta, sourceProject, sourceselector, destFolder, toCopy, notToCopy)
|
||||
artifactFetched.put(artifactKey, importmeta)
|
||||
}
|
||||
}
|
||||
return artifactFetched
|
||||
}
|
||||
|
||||
// Export any required binaries to the <WORKSPACE>/bin folder
|
||||
def exportBinaries(artifactDetails, installerDetails) {
|
||||
def placeBinaries(artifactDetails, installerDetails) {
|
||||
for (installer in toBuild) {
|
||||
(artifactSet, targetFolder, executionPath, ISMprojectFile, installerVariant, exportBinaries) = installerDetails.get(installer)
|
||||
if (exportBinaries) {
|
||||
693
meta/folder.groovy
Normal file
693
meta/folder.groovy
Normal file
|
|
@ -0,0 +1,693 @@
|
|||
import java.nio.file.Paths
|
||||
import java.nio.file.Path
|
||||
|
||||
abstract class GISJsonSerialised implements Serializable {
|
||||
def script
|
||||
|
||||
GISJsonSerialised(script) {
|
||||
this.script = script
|
||||
}
|
||||
|
||||
abstract LinkedHashMap serialisationdata()
|
||||
|
||||
abstract void deserialiseJson(rawmeta)
|
||||
|
||||
def saveJsonSerialised(String outputfile, int prettylevel = 4) {
|
||||
def outJson = script.readJSON text: groovy.json.JsonOutput.toJson(serialisationdata())
|
||||
script.writeJSON(file: outputfile, json: outJson, pretty: prettylevel)
|
||||
}
|
||||
}
|
||||
|
||||
class ProductInfo extends GISJsonSerialised {
|
||||
String productname
|
||||
String subcomponentname
|
||||
String jirakey
|
||||
|
||||
ProductInfo(script, productname = "", subcomponentname = "", jirakey = "") {
|
||||
super(script)
|
||||
this.productname = productname
|
||||
this.subcomponentname = subcomponentname
|
||||
this.jirakey = jirakey
|
||||
}
|
||||
|
||||
void set(String productname, String subcomponentname, String jirakey) {
|
||||
// Make sure the fields can be used in git tags
|
||||
def int pstatus = 0
|
||||
if (script.isUnix()) {
|
||||
pstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${productname}\" >/dev/null 2>/dev/null", , returnStatus: true)
|
||||
}
|
||||
else {
|
||||
pstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${productname}\" > NUL 2> NUL", , returnStatus: true)
|
||||
}
|
||||
if (pstatus > 0) {
|
||||
script.error("The product name: ${productname} needs to be renamed as it cannot be used in a git tag name")
|
||||
}
|
||||
def int sstatus = 0
|
||||
if (script.isUnix()) {
|
||||
sstatus = script.sh(script: "git check-ref-format --normalize \"refs/tags/${subcomponentname}\" >/dev/null 2>/dev/null", , returnStatus: true)
|
||||
}
|
||||
else {
|
||||
sstatus = script.bat(script: "@git check-ref-format --normalize \"refs/tags/${subcomponentname}\" > NUL 2> NUL", , returnStatus: true)
|
||||
}
|
||||
if (sstatus > 0) {
|
||||
script.error("The subcomponent name: ${subcomponentname} needs to be renamed as it cannot be used in a git tag name")
|
||||
}
|
||||
this.productname = productname
|
||||
this.subcomponentname = subcomponentname
|
||||
this.jirakey = jirakey
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
productname = rawmeta['productname']
|
||||
subcomponentname = rawmeta['subcomponentname']
|
||||
jirakey = rawmeta['jirakey']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'productname' : productname,
|
||||
'subcomponentname' : subcomponentname,
|
||||
'jirakey' : jirakey,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class GitInfo extends GISJsonSerialised {
|
||||
private String sourcepath
|
||||
private String sourcerevision
|
||||
private String gitrevision
|
||||
private String remoteurl
|
||||
private String remoteinfo
|
||||
|
||||
GitInfo(script, sourcepath = "", sourcerevision = "", gitrevision = "", remoteurl = "", remoteinfo = "") {
|
||||
super(script)
|
||||
this.sourcepath = sourcepath
|
||||
this.sourcerevision = sourcerevision
|
||||
this.gitrevision = gitrevision
|
||||
this.remoteurl = remoteurl
|
||||
this.remoteinfo = remoteinfo
|
||||
}
|
||||
|
||||
void set(String sourcepath, String sourcerevision, String gitrevision, String remoteurl, String remoteinfo) {
|
||||
this.sourcepath = sourcepath
|
||||
this.sourcerevision = sourcerevision
|
||||
this.gitrevision = gitrevision
|
||||
this.remoteurl = remoteurl
|
||||
this.remoteinfo = remoteinfo
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
sourcepath = rawmeta['sourcepath']
|
||||
sourcerevision = rawmeta['sourcerevision']
|
||||
gitrevision = rawmeta['gitrevision']
|
||||
remoteurl = rawmeta['remoteurl']
|
||||
remoteinfo = rawmeta['remoteinfo']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'sourcepath' : sourcepath,
|
||||
'sourcerevision' : sourcerevision,
|
||||
'gitrevision' : gitrevision,
|
||||
'remoteurl' : remoteurl,
|
||||
'remoteinfo' : remoteinfo,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class JenkinsBuildInfo extends GISJsonSerialised {
|
||||
private String buildjobname
|
||||
private int buildnumber
|
||||
private String buildmachine
|
||||
private String builddate
|
||||
|
||||
JenkinsBuildInfo(script, String buildjobname = "", int buildnumber = 0, String buildmachine = "", String builddate = "") {
|
||||
super(script)
|
||||
this.buildjobname = buildjobname
|
||||
this.buildnumber = buildnumber
|
||||
this.buildmachine = buildmachine
|
||||
this.builddate = builddate
|
||||
}
|
||||
|
||||
void set(String buildjobname, int buildnumber, String buildmachine, String builddate) {
|
||||
this.buildjobname = buildjobname
|
||||
this.buildnumber = buildnumber
|
||||
this.buildmachine = buildmachine
|
||||
this.builddate = builddate
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
buildjobname = rawmeta['buildjobname']
|
||||
buildnumber = rawmeta['buildnumber']
|
||||
buildmachine = rawmeta['buildmachine']
|
||||
builddate = rawmeta['builddate']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'buildjobname' : buildjobname,
|
||||
'buildnumber' : buildnumber,
|
||||
'buildmachine' : buildmachine,
|
||||
'builddate' : builddate,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class BuildStampInfo extends GISJsonSerialised {
|
||||
private String buildstampprefix
|
||||
int revision
|
||||
String buildstamp
|
||||
|
||||
BuildStampInfo(script, buildstampprefix = "1.30000.0.", revision = 0, buildstamp = "1.30000.0.0") {
|
||||
super(script)
|
||||
this.buildstampprefix = buildstampprefix
|
||||
this.revision = revision
|
||||
this.buildstamp = buildstamp
|
||||
}
|
||||
|
||||
void set(String buildstampprefix, int revision, String buildstamp) {
|
||||
this.buildstampprefix = buildstampprefix
|
||||
this.revision = revision
|
||||
this.buildstamp = buildstamp
|
||||
}
|
||||
|
||||
String buildstampcommasep() {
|
||||
def String buildstampcommasep = buildstamp.replace(".", ",")
|
||||
return buildstampcommasep
|
||||
}
|
||||
|
||||
void changerevision(int newrevision) {
|
||||
script.echo("Build stamp currently ${buildstamp}")
|
||||
revision = newrevision
|
||||
def List buildstampsplit = buildstamp.split('\\.')
|
||||
buildstampsplit[-1] = newrevision.toString()
|
||||
buildstamp = buildstampsplit.join('.')
|
||||
script.echo("Build stamp now ${buildstamp}")
|
||||
}
|
||||
|
||||
void set(String buildstampprefix, int revision) {
|
||||
buildstampprefix += buildstampprefix.endsWith('.') ? '' : '.'
|
||||
this.buildstampprefix = buildstampprefix
|
||||
this.buildstamp = buildstampprefix + "0"
|
||||
changerevision(revision)
|
||||
}
|
||||
|
||||
void set(String buildstampprefix, String revision) {
|
||||
set(buildstampprefix, revision.toInteger())
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
buildstampprefix = rawmeta['buildstampprefix']
|
||||
revision = rawmeta['revision']
|
||||
buildstamp = rawmeta['buildstamp']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'buildstampprefix' : buildstampprefix,
|
||||
'revision' : revision,
|
||||
'buildstamp' : buildstamp,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class ReleaseInfo extends GISJsonSerialised {
|
||||
String releaserepoURL
|
||||
ArrayList<String> releaseitems
|
||||
|
||||
ReleaseInfo(script, releaserepoURL = "") {
|
||||
super(script)
|
||||
this.releaserepoURL = releaserepoURL
|
||||
this.releaseitems = new ArrayList<String>()
|
||||
}
|
||||
|
||||
void set(String releaserepoURL = "") {
|
||||
this.releaserepoURL = releaserepoURL
|
||||
}
|
||||
|
||||
void addReleaseItem(String releaseitem) {
|
||||
releaseitems.add(releaseitem)
|
||||
}
|
||||
|
||||
List releaseitemssserialised() {
|
||||
def items = []
|
||||
for (ri in releaseitems) {
|
||||
items.add(ri)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
releaserepoURL = rawmeta['releaserepoURL']
|
||||
releaseitems = new ArrayList<String>()
|
||||
for (rawreleaseitem in rawmeta['releaseitems']) {
|
||||
releaseitems.add(rawreleaseitem)
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'releaserepoURL' : releaserepoURL,
|
||||
'releaseitems' : releaseitemssserialised(),
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigurationInfo extends GISJsonSerialised {
|
||||
private String configurationname
|
||||
private String configurationURL
|
||||
private String configurationversion
|
||||
private String configurationSHA
|
||||
|
||||
ConfigurationInfo(script, configurationname = "", configurationURL = "", configurationversion = "", configurationSHA = "") {
|
||||
super(script)
|
||||
this.configurationname = configurationname
|
||||
this.configurationURL = configurationURL
|
||||
this.configurationversion = configurationversion
|
||||
this.configurationSHA = configurationSHA
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
configurationname = rawmeta['configurationname']
|
||||
configurationURL = rawmeta['configurationURL']
|
||||
configurationversion = rawmeta['configurationversion']
|
||||
configurationSHA = rawmeta['configurationSHA']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'configurationname' : configurationname,
|
||||
'configurationURL' : configurationURL,
|
||||
'configurationversion' : configurationversion,
|
||||
'configurationSHA' : configurationSHA,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class ChecksumPair extends GISJsonSerialised {
|
||||
private String filepath
|
||||
private String sum
|
||||
|
||||
ChecksumPair(script, String filepath = "", String sum = "") {
|
||||
super(script)
|
||||
this.filepath = filepath
|
||||
this.sum = sum
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
filepath = rawmeta['filepath']
|
||||
sum = rawmeta['sum']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'filepath' : filepath,
|
||||
'sum' : sum,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class ChecksumSet extends GISJsonSerialised {
|
||||
private String artifactpath
|
||||
private ArrayList<ChecksumPair> checksumpairs
|
||||
|
||||
ChecksumSet(script, artifactpath = "") {
|
||||
super(script)
|
||||
this.artifactpath = artifactpath
|
||||
checksumpairs = new ArrayList<ChecksumPair>()
|
||||
}
|
||||
|
||||
ChecksumPair addChecksumPair(String filepath, String sum) {
|
||||
def cp = new ChecksumPair(script, filepath, sum)
|
||||
checksumpairs.add(cp)
|
||||
return cp
|
||||
}
|
||||
|
||||
List checksumpairsserialised() {
|
||||
def associated = []
|
||||
for (cp in checksumpairs) {
|
||||
associated.add(cp.serialisationdata())
|
||||
}
|
||||
return associated
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
artifactpath = rawmeta['artifactpath']
|
||||
checksumpairs = new ArrayList<ChecksumPair>()
|
||||
for (rawchecksumpair in rawmeta['checksumpairs']) {
|
||||
def csp = new ChecksumPair(script)
|
||||
csp.deserialiseJson(rawchecksumpair)
|
||||
checksumpairs.add(csp)
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'artifactpath' : artifactpath,
|
||||
'checksumpairs' : checksumpairsserialised(),
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class ChecksumInfo extends GISJsonSerialised {
|
||||
private ArrayList<ChecksumSet> checksumsets
|
||||
|
||||
ChecksumInfo(script) {
|
||||
super(script)
|
||||
checksumsets = new ArrayList<ChecksumSet>()
|
||||
}
|
||||
|
||||
ChecksumSet addChecksumSet(String artifactpath) {
|
||||
def cs = new ChecksumSet(script, artifactpath)
|
||||
checksumsets.add(cs)
|
||||
return cs
|
||||
}
|
||||
|
||||
List checksumsetsserialised() {
|
||||
def associated = []
|
||||
for (cs in checksumsets) {
|
||||
associated.add(cs.serialisationdata())
|
||||
}
|
||||
return associated
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
checksumsets = new ArrayList<ChecksumSet>()
|
||||
for (rawchecksumset in rawmeta['checksumsets']) {
|
||||
def cs = new ChecksumSet(script)
|
||||
cs.deserialiseJson(rawchecksumset)
|
||||
checksumsets.add(cs)
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'checksumsets' : checksumsetsserialised(),
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class PublishableInfo extends GISJsonSerialised {
|
||||
private String filepath
|
||||
|
||||
PublishableInfo(script, String filepath = "") {
|
||||
super(script)
|
||||
this.filepath = filepath
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
filepath = rawmeta['filepath']
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'filepath' : filepath,
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
class MetaInfo extends GISJsonSerialised {
|
||||
private static String FORMAT = "0.1"
|
||||
private static String METAFOLDERNAME = "meta"
|
||||
private static String METAFILENAME = "info.json"
|
||||
private static String METADIFFFILENAME = "differences.txt"
|
||||
private static String METAARTIFACTS = "${METAFOLDERNAME}/**"
|
||||
|
||||
class RelatedMetaInfo extends GISJsonSerialised {
|
||||
String offsetpath
|
||||
MetaInfo meta
|
||||
|
||||
RelatedMetaInfo(script, offsetpath = "", MetaInfo meta = null) {
|
||||
super(script)
|
||||
this.offsetpath = offsetpath
|
||||
this.meta = meta
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
offsetpath = rawmeta['offsetpath']
|
||||
meta = new MetaInfo(script)
|
||||
meta.deserialiseJson(rawmeta['meta'])
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'offsetpath' : offsetpath,
|
||||
'meta' : meta.serialisationdata(),
|
||||
]
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
private String format = FORMAT
|
||||
ProductInfo productinfo
|
||||
GitInfo gitinfo
|
||||
JenkinsBuildInfo jenkinsbuildinfo
|
||||
BuildStampInfo buildstampinfo
|
||||
ReleaseInfo releaseinfo
|
||||
ChecksumInfo checksuminfo
|
||||
private ArrayList<ConfigurationInfo> configurationinfo
|
||||
private ArrayList<PublishableInfo> publishableinfo
|
||||
private LinkedHashMap<String, String> custominfo
|
||||
private ArrayList<RelatedMetaInfo> associatedmeta
|
||||
|
||||
MetaInfo(script) {
|
||||
super(script)
|
||||
productinfo = new ProductInfo(script)
|
||||
gitinfo = new GitInfo(script)
|
||||
jenkinsbuildinfo = new JenkinsBuildInfo(script)
|
||||
buildstampinfo = new BuildStampInfo(script)
|
||||
releaseinfo = new ReleaseInfo(script)
|
||||
checksuminfo = new ChecksumInfo(script)
|
||||
configurationinfo = new ArrayList<ConfigurationInfo>()
|
||||
publishableinfo = new ArrayList<PublishableInfo>()
|
||||
custominfo = new LinkedHashMap<String, String>()
|
||||
associatedmeta = new ArrayList<RelatedMetaInfo>()
|
||||
}
|
||||
|
||||
List configurationinfoserialised() {
|
||||
def configuration = []
|
||||
for (configurationitem in configurationinfo) {
|
||||
configuration.add(configurationitem.serialisationdata())
|
||||
}
|
||||
return configuration
|
||||
}
|
||||
|
||||
void addPublishable(String filepath) {
|
||||
def PublishableInfo pi = new PublishableInfo(script, filepath)
|
||||
publishableinfo.add(pi)
|
||||
}
|
||||
|
||||
void addConfigurationInfo(String configurationname, String configurationURL, String configurationversion, String configurationSHA) {
|
||||
def ConfigurationInfo ci = new ConfigurationInfo(script, configurationname, configurationURL, configurationversion, configurationSHA)
|
||||
configurationinfo.add(ci)
|
||||
}
|
||||
|
||||
void addCustomInfo(String customId, String customValue) {
|
||||
custominfo.put(customId.trim(), customValue)
|
||||
}
|
||||
|
||||
String getCustomInfo(String customId) {
|
||||
return custominfo.getAt(customId.trim())
|
||||
}
|
||||
|
||||
List publishableinfoserialised() {
|
||||
def publishable = []
|
||||
for (publishableitem in publishableinfo) {
|
||||
publishable.add(publishableitem.serialisationdata())
|
||||
}
|
||||
return publishable
|
||||
}
|
||||
|
||||
List associatedmetaserialised() {
|
||||
def associated = []
|
||||
for (metaitem in associatedmeta) {
|
||||
associated.add(metaitem.serialisationdata())
|
||||
}
|
||||
return associated
|
||||
}
|
||||
|
||||
void deserialiseJson(rawmeta) {
|
||||
if (rawmeta['format'] != FORMAT) {
|
||||
script.error("Unsupported meta format found at ${filepath}")
|
||||
return
|
||||
}
|
||||
productinfo.deserialiseJson(rawmeta['productinfo'])
|
||||
gitinfo.deserialiseJson(rawmeta['gitinfo'])
|
||||
jenkinsbuildinfo.deserialiseJson(rawmeta['jenkinsbuildinfo'])
|
||||
buildstampinfo.deserialiseJson(rawmeta['buildstampinfo'])
|
||||
releaseinfo.deserialiseJson(rawmeta['releaseinfo'])
|
||||
checksuminfo.deserialiseJson(rawmeta['checksuminfo'])
|
||||
for (rawconfig in rawmeta['configuration']) {
|
||||
def cf = new ConfigurationInfo(script)
|
||||
cf.deserialiseJson(rawconfig)
|
||||
configurationinfo.add(cf)
|
||||
}
|
||||
for (rawpublishable in rawmeta['publishableinfo']) {
|
||||
def pb = new PublishableInfo(script)
|
||||
pb.deserialiseJson(rawpublishable)
|
||||
publishableinfo.add(pb)
|
||||
}
|
||||
custominfo = rawmeta['custominfo']
|
||||
for (rawrelatedmeta in rawmeta['associatedmeta']) {
|
||||
def rm = new RelatedMetaInfo(script)
|
||||
rm.deserialiseJson(rawrelatedmeta)
|
||||
associatedmeta.add(rm)
|
||||
}
|
||||
}
|
||||
|
||||
def deserialiseJson(String filepath) {
|
||||
def rawmeta = script.readJSON(file: filepath)
|
||||
deserialiseJson(rawmeta)
|
||||
}
|
||||
|
||||
String relativize(String path) {
|
||||
def Path thispath = Paths.get(path)
|
||||
if (thispath.startsWith(script.WORKSPACE)) {
|
||||
def Path wspath = Paths.get(script.WORKSPACE)
|
||||
def Path wsrelativePath = wspath.relativize(thispath)
|
||||
return wsrelativePath.toString()
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
static String metafilepath() {
|
||||
return METAFOLDERNAME + "/" + METAFILENAME
|
||||
}
|
||||
|
||||
static String difffilepath() {
|
||||
return METAFOLDERNAME + "/" + METADIFFFILENAME
|
||||
}
|
||||
|
||||
MetaInfo importrelated(String destpath) {
|
||||
MetaInfo mi = new MetaInfo(script)
|
||||
|
||||
def String adjustedpath = relativize(destpath)
|
||||
def importedmetafile = adjustedpath + "/" + metafilepath()
|
||||
if (script.fileExists(importedmetafile)) {
|
||||
mi.deserialiseJson(importedmetafile)
|
||||
}
|
||||
|
||||
RelatedMetaInfo rmi = new RelatedMetaInfo(script, adjustedpath, mi)
|
||||
associatedmeta.add(rmi)
|
||||
|
||||
def importedmetadifffile = adjustedpath + "/" + difffilepath()
|
||||
if (script.fileExists(importedmetadifffile)) {
|
||||
def String newcontents = script.readFile(file: importedmetadifffile)
|
||||
def String currentcontents = ""
|
||||
if (script.fileExists(difffilepath())) {
|
||||
currentcontents = script.readFile(file: difffilepath())
|
||||
}
|
||||
|
||||
script.writeFile(file: difffilepath(), text: currentcontents + "\n" + mi.productinfo.productname + " " + mi.productinfo.subcomponentname + ":\n" + newcontents)
|
||||
}
|
||||
|
||||
return mi
|
||||
}
|
||||
|
||||
LinkedHashMap serialisationdata() {
|
||||
def data = [
|
||||
'format' : format,
|
||||
'productinfo' : productinfo.serialisationdata(),
|
||||
'gitinfo' : gitinfo.serialisationdata(),
|
||||
'jenkinsbuildinfo' : jenkinsbuildinfo.serialisationdata(),
|
||||
'buildstampinfo' : buildstampinfo.serialisationdata(),
|
||||
'releaseinfo' : releaseinfo.serialisationdata(),
|
||||
'configuration' : configurationinfoserialised(),
|
||||
'checksuminfo' : checksuminfo.serialisationdata(),
|
||||
'publishableinfo' : publishableinfoserialised(),
|
||||
'custominfo' : custominfo,
|
||||
'associatedmeta' : associatedmetaserialised(),
|
||||
]
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
static String folder() {
|
||||
return METAFOLDERNAME
|
||||
}
|
||||
|
||||
String generateartifacts(ArrayList<String> releasedfromhere = new ArrayList<String>(), // These items are recorded in meta as released from here
|
||||
ArrayList<String> releasedfromsubmeta = new ArrayList<String>(), // These items are not recorded in meta as released from here
|
||||
String metafilepath ="${METAFOLDERNAME}/${METAFILENAME}"
|
||||
) {
|
||||
def String artifactlist = METAARTIFACTS
|
||||
releaseinfo.addReleaseItem(METAARTIFACTS)
|
||||
for (releaseitem in releasedfromhere) {
|
||||
artifactlist += "," + releaseitem
|
||||
releaseinfo.addReleaseItem(releaseitem)
|
||||
}
|
||||
for (releaseitem in releasedfromsubmeta) {
|
||||
artifactlist += "," + releaseitem
|
||||
}
|
||||
saveJsonSerialised(metafilepath)
|
||||
return artifactlist
|
||||
}
|
||||
|
||||
// Recurse tree of meta looking for release info and accumulate path - Pass by reference unavailable in Groovy/Java
|
||||
private ArrayList<RelatedMetaInfo> releasewalkerp(int maxdepth, ArrayList<RelatedMetaInfo> releasemetacollection, String pathsofar) {
|
||||
if (maxdepth > 0) {
|
||||
if (releaseinfo.releaserepoURL) {
|
||||
RelatedMetaInfo rmi = new RelatedMetaInfo(script, pathsofar, this)
|
||||
releasemetacollection.add(rmi)
|
||||
}
|
||||
if (pathsofar) {
|
||||
pathsofar += "/"
|
||||
}
|
||||
for (relatedmetainfo in associatedmeta) {
|
||||
MetaInfo othermeta = relatedmetainfo.meta
|
||||
String newpathsofar = pathsofar + relatedmetainfo.offsetpath
|
||||
releasemetacollection = othermeta.releasewalkerp(maxdepth - 1, releasemetacollection, newpathsofar)
|
||||
}
|
||||
}
|
||||
return releasemetacollection
|
||||
}
|
||||
|
||||
ArrayList<RelatedMetaInfo> releasewalker(int maxdepth, String startpath = "") {
|
||||
ArrayList<RelatedMetaInfo> releasemetacollection = new ArrayList<RelatedMetaInfo>()
|
||||
releasemetacollection = releasewalkerp(maxdepth, releasemetacollection, startpath)
|
||||
return releasemetacollection
|
||||
}
|
||||
|
||||
Map<String, RelatedMetaInfo> releasewalkerunique(int maxdepth, String startpath = "") {
|
||||
Map<String, RelatedMetaInfo> releasemetauniquecollection = new LinkedHashMap<String, RelatedMetaInfo>()
|
||||
ArrayList<RelatedMetaInfo> releasemetacollection = new ArrayList<RelatedMetaInfo>()
|
||||
releasemetacollection = releasewalkerp(maxdepth, releasemetacollection, startpath)
|
||||
for (relatedmetainfo in releasemetacollection) {
|
||||
String uniquestring = relatedmetainfo.meta.productinfo.productname + "_" + relatedmetainfo.meta.productinfo.subcomponentname
|
||||
releasemetauniquecollection.put(uniquestring, relatedmetainfo)
|
||||
}
|
||||
return releasemetauniquecollection
|
||||
}
|
||||
|
||||
MetaInfo getNewMetaObject(script) {
|
||||
return new MetaInfo(script)
|
||||
}
|
||||
}
|
||||
|
||||
MetaInfo metareset(script) {
|
||||
echo "Resetting meta folder"
|
||||
def mi = new MetaInfo(script)
|
||||
|
||||
dir(mi.folder()) {
|
||||
deleteDir()
|
||||
}
|
||||
return mi
|
||||
}
|
||||
|
||||
MetaInfo metafromfolder(String folder = "") {
|
||||
MetaInfo buildmeta = new MetaInfo(this)
|
||||
buildmeta.deserialiseJson("${folder}/${MetaInfo.metafilepath()}")
|
||||
return buildmeta
|
||||
}
|
||||
|
||||
return this;
|
||||
5
platform/lineendings.groovy
Normal file
5
platform/lineendings.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
// Put ${nl} into strings when wanting a newline
|
||||
nl = System.properties['line.separator']
|
||||
|
||||
return this;
|
||||
124
publish/do.groovy
Normal file
124
publish/do.groovy
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
markunstable = false
|
||||
unstablereason = ""
|
||||
|
||||
summaryfolder = "${WORKSPACE}/summary"
|
||||
summaryfile = "${summaryfolder}/summary.txt"
|
||||
summarystring = ""
|
||||
releaserepofolder = "${WORKSPACE}/releaserepos"
|
||||
tempfolder = "${WORKSPACE}/temp"
|
||||
|
||||
def resetfolders() {
|
||||
dir(summaryfolder) {
|
||||
deleteDir()
|
||||
}
|
||||
dir(releaserepofolder) {
|
||||
deleteDir()
|
||||
}
|
||||
dir(tempfolder) {
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
|
||||
def preconditions() {
|
||||
markunstable = false
|
||||
unstablereason = ""
|
||||
summarystring = ""
|
||||
writeFile(file: summaryfile, text: "Publish summary: \n")
|
||||
}
|
||||
|
||||
def setunstable(String reason) {
|
||||
markunstable = true
|
||||
unstablereason = reason
|
||||
}
|
||||
|
||||
def summaryappend(String summary) {
|
||||
def String currentsummarycontents = readFile(file: summaryfile)
|
||||
writeFile(file: summaryfile, text: currentsummarycontents + summary)
|
||||
summarystring += summary
|
||||
}
|
||||
|
||||
gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
|
||||
def getcomponentartifacts(releaseinfo, String repofolder, String tempfolder) {
|
||||
// Copy relevant artifacts to temp folder
|
||||
summaryappend("Artifacts: ")
|
||||
|
||||
def releasemeta = releaseinfo.meta
|
||||
def String componentURL = releasemeta.releaseinfo.releaserepoURL
|
||||
def String revision = "refs/tags/${releasemeta.buildstampinfo.buildstamp}"
|
||||
def publishableitems = releasemeta.publishableinfo
|
||||
def ArrayList<String> publishablePaths = new ArrayList<String>()
|
||||
if (publishableitems.size() > 0) {
|
||||
for (publishableitem in publishableitems) {
|
||||
publishablePaths.add(publishableitem.filepath)
|
||||
summaryappend("${publishableitem.filepath},")
|
||||
}
|
||||
gh.gitCheckout(componentURL, revision, repofolder, "", 1, true, publishablePaths) // Shallow clone
|
||||
}
|
||||
else {
|
||||
summaryappend("None ")
|
||||
}
|
||||
}
|
||||
|
||||
def publish(String customer) {
|
||||
summaryappend(" FTP operations: ")
|
||||
|
||||
def String FTP_CLIENT_LOCATION='ftp'
|
||||
def String FTP_URL='ie1.hostedftp.com'
|
||||
def String FTP_USER='ftp@globalinkjetsystems.com'
|
||||
def String FTP_CUSTOMER_ROOT="/Customers/${customer}"
|
||||
def String FTP_PASSWORD='ramshorn42'
|
||||
dir(releaserepofolder) {
|
||||
summaryappend("FTP operations: Transferring to ${FTP_CUSTOMER_ROOT}")
|
||||
sh """#!/bin/bash
|
||||
ncftpput -u ${FTP_USER} -p ${FTP_PASSWORD} -R ${FTP_URL} "${FTP_CUSTOMER_ROOT}" .
|
||||
"""
|
||||
summaryappend(", Transferred ")
|
||||
}
|
||||
}
|
||||
|
||||
def recallcomponent(releaseinfo, String softwarerelease) {
|
||||
def releasemeta = releaseinfo.meta
|
||||
def String uniquefolder = "Software/${PRODUCT_NAME} ${software_release}/${releasemeta.productinfo.productname}_${releasemeta.productinfo.subcomponentname}"
|
||||
def String uniquefolderforrepo = "${releaserepofolder}/${uniquefolder}"
|
||||
def String uniquefoldertemp = "${tempfolder}/${uniquefolder}"
|
||||
|
||||
summaryappend("${releasemeta.productinfo.productname} ${releasemeta.productinfo.subcomponentname}: ")
|
||||
|
||||
getcomponentartifacts(releaseinfo, uniquefolderforrepo, uniquefoldertemp)
|
||||
|
||||
summaryappend("\n")
|
||||
}
|
||||
|
||||
def stripgithistory() {
|
||||
echo "Stripping git history out of ${releaserepofolder}"
|
||||
dir(releaserepofolder) {
|
||||
sh """#!/bin/bash
|
||||
pwd
|
||||
find . -type d -name ".git" | xargs -iXX rm -rvf XX
|
||||
find . -name ".gitignore" | xargs -iXX rm -rvf XX
|
||||
find . -name ".gitmodules" | xargs -iXX rm -rvf XX
|
||||
find . -iname ".gitattributes" | xargs -iXX rm -rvf XX
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
def publishhierarchy(releasemeta, String customer, String softwarerelease, String maxdepth) {
|
||||
int md = maxdepth.toInteger()
|
||||
resetfolders()
|
||||
preconditions()
|
||||
|
||||
// Walk the meta information to a max depth, looking for artifacts to import for release
|
||||
componentReleaseInfo = releasemeta.releasewalkerunique(md)
|
||||
|
||||
// For each component
|
||||
for (key in componentReleaseInfo.keySet()) {
|
||||
def releaseinfo = componentReleaseInfo[key]
|
||||
recallcomponent(releaseinfo, softwarerelease)
|
||||
}
|
||||
stripgithistory()
|
||||
publish(customer)
|
||||
|
||||
return [summarystring, markunstable, unstablereason]
|
||||
}
|
||||
|
||||
return this;
|
||||
90
publish/publish.groovy
Normal file
90
publish/publish.groovy
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
pipeline {
|
||||
agent { label "${AGENT_LABEL}" }
|
||||
stages {
|
||||
stage('Initial setup') {
|
||||
steps {
|
||||
script {
|
||||
autobuilderscript = load("${WORKSPACE}/autobuild/Common_scripts/autobuilder.groovy")
|
||||
meta = autobuilderscript.start(this, PRODUCT_NAME, SUBCOMPONENT_NAME, JIRA_KEY, RELEASE_REPO)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Clean folders') {
|
||||
steps {
|
||||
script {
|
||||
cleanfolders = [
|
||||
]
|
||||
cleaner = load("${autobuilder.commonscripts()}/clean/clean.groovy")
|
||||
cleaner.clean(cleanfolders)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Checkout release repo') {
|
||||
steps {
|
||||
script {
|
||||
configurationhelper = autobuilder.configurationhelper()
|
||||
|
||||
SOURCEURL = RELEASE_REPO
|
||||
SOURCEREVISION = "refs/tags/${SOFTWARE_RELEASE}"
|
||||
SOURCEDIR = "${WORKSPACE}/whole"
|
||||
SOURCEROOTDIR = 'whole'
|
||||
configurationhelper.gitCheckoutAndRegister(meta, 'whole', SOURCEURL, SOURCEREVISION, SOURCEDIR, SOURCEROOTDIR, 0, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Get release artifact meta') {
|
||||
steps {
|
||||
script {
|
||||
def mfs = autobuilderscript.getmetafolderscript()
|
||||
releasemeta = mfs.metafromfolder(SOURCEDIR)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Publish components') {
|
||||
steps {
|
||||
script {
|
||||
def publisher = load("${autobuilder.commonscripts()}/publish/do.groovy")
|
||||
MAX_META_DEPTH='2'
|
||||
(summarystring, markunstable, unstablereason) = publisher.publishhierarchy(releasemeta, CUSTOMER, SOFTWARE_RELEASE, MAX_META_DEPTH)
|
||||
if (markunstable) {
|
||||
env.unstablereason = unstablereason
|
||||
currentBuild.result = 'UNSTABLE'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Archiving artifacts') {
|
||||
steps {
|
||||
script {
|
||||
def artifactlist = meta.generateartifacts()
|
||||
archiveArtifacts "summary/**,${artifactlist}"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Summarise') {
|
||||
steps {
|
||||
script {
|
||||
echo "Summary:\n${summarystring}\n"
|
||||
if (env.unstablereason) {
|
||||
echo "Instability reason: ${env.unstablereason}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
echo 'Post-build'
|
||||
}
|
||||
failure {
|
||||
echo 'Failed build'
|
||||
}
|
||||
unstable {
|
||||
echo 'Unstable build'
|
||||
}
|
||||
success {
|
||||
echo 'Succeeded build'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
publishing/utils.groovy
Normal file
10
publishing/utils.groovy
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
// Generate a list of artifact files that are publishable to outside parties
|
||||
def generatelist(meta, publishable) {
|
||||
filelist = []
|
||||
for (filepath in publishable) {
|
||||
meta.addPublishable(filepath)
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
350
release/do.groovy
Normal file
350
release/do.groovy
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
markunstable = false
|
||||
unstablereason = ""
|
||||
|
||||
summaryfolder = "${WORKSPACE}/summary"
|
||||
summaryfile = "${summaryfolder}/summary.txt"
|
||||
summarystring = ""
|
||||
releaserepofolder = "${WORKSPACE}/releaserepos"
|
||||
sourcerepofolder = "${WORKSPACE}/sourcerepos"
|
||||
tempfolder = "${WORKSPACE}/temp"
|
||||
gitrevparseoutputfile = "${tempfolder}/gitrevparse.out"
|
||||
|
||||
metascript = autobuilder.getmetafolderscript()
|
||||
|
||||
def resetfolders() {
|
||||
dir(summaryfolder) {
|
||||
deleteDir()
|
||||
}
|
||||
dir(releaserepofolder) {
|
||||
deleteDir()
|
||||
}
|
||||
dir(tempfolder) {
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
|
||||
def preconditions() {
|
||||
markunstable = false
|
||||
unstablereason = ""
|
||||
summarystring = ""
|
||||
writeFile(file: summaryfile, text: "Release summary: \n")
|
||||
}
|
||||
|
||||
def setunstable(String reason) {
|
||||
markunstable = true
|
||||
unstablereason = reason
|
||||
}
|
||||
|
||||
def summaryappend(String summary) {
|
||||
def String currentsummarycontents = readFile(file: summaryfile)
|
||||
writeFile(file: summaryfile, text: currentsummarycontents + summary)
|
||||
summarystring += summary
|
||||
}
|
||||
|
||||
def getpreviousreleasemeta(buildmeta, String checkoutfolder) {
|
||||
def previousreleasemeta = buildmeta.getNewMetaObject(this)
|
||||
// See if there is meta data file from the current release
|
||||
def String releasemetafolderpath = "${checkoutfolder}/${buildmeta.folder()}"
|
||||
if (fileExists(releasemetafolderpath)) {
|
||||
previousreleasemeta = metascript.metafromfolder(checkoutfolder)
|
||||
}
|
||||
return previousreleasemeta
|
||||
}
|
||||
|
||||
def checkoutreleaserepo(buildmeta, String checkoutfolder) {
|
||||
def String releaserepo = buildmeta.releaseinfo.releaserepoURL
|
||||
// Get the latest head revision of the release repo without checking out working copy; Check out to a folder unique to component; Extract any meta
|
||||
def previousreleasemeta = buildmeta.getNewMetaObject(this)
|
||||
dir(releaserepofolder) {
|
||||
sh("git clone --depth 1 ${releaserepo} ${checkoutfolder}")
|
||||
}
|
||||
previousreleasemeta = getpreviousreleasemeta(buildmeta, checkoutfolder)
|
||||
dir(checkoutfolder) {
|
||||
// Clear all existing files
|
||||
sh("git rm -r *")
|
||||
}
|
||||
return previousreleasemeta
|
||||
}
|
||||
|
||||
def checkoutsourcerepo(buildmeta, String checkoutfolder) {
|
||||
def String sourcerepo = buildmeta.gitinfo.remoteurl
|
||||
if (sourcerepo) {
|
||||
// Get the latest revision of the source repo without checking out working copy; Check out to a folder unique to component
|
||||
if (fileExists(checkoutfolder)) {
|
||||
dir(checkoutfolder) {
|
||||
sh("""
|
||||
git reset --hard
|
||||
git clean -fdx
|
||||
git pull
|
||||
# Remove all tags that are not already on the remote
|
||||
git tag -l | xargs git tag -d >/dev/null
|
||||
git fetch -t >/dev/null
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
dir(sourcerepofolder) {
|
||||
sh("git clone ${sourcerepo} ${checkoutfolder}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def getcomponentartifacts(buildinfo, String repofolder, String tempfolder) {
|
||||
// Copy relevant artifacts to temp folder
|
||||
summaryappend("Artifacts: ")
|
||||
for (artifactfilter in buildinfo.meta.releaseinfo.releaseitems) {
|
||||
def filterpath = artifactfilter
|
||||
if (buildinfo.offsetpath) {
|
||||
filterpath = buildinfo.offsetpath + '/' + artifactfilter
|
||||
}
|
||||
// Copy relevant artifacts to temp folder
|
||||
echo "Copying artifacts: ${filterpath} to ${tempfolder}"
|
||||
copyArtifacts(
|
||||
filter: filterpath,
|
||||
projectName: BUILD_JOB,
|
||||
selector: [
|
||||
$class: 'ParameterizedBuildSelector',
|
||||
parameterName: BUILD_JOB_SELECTOR
|
||||
],
|
||||
target: tempfolder
|
||||
)
|
||||
// Move relevant artifacts from temp folder to release position
|
||||
def originalrootdir = tempfolder + "/" + buildinfo.offsetpath
|
||||
dir(originalrootdir) {
|
||||
sh("mv * ${repofolder}")
|
||||
}
|
||||
summaryappend("${artifactfilter},")
|
||||
}
|
||||
}
|
||||
|
||||
def releasegitadd() {
|
||||
// Add anything new
|
||||
sh("git add .")
|
||||
summaryappend("Add,")
|
||||
}
|
||||
|
||||
def releasegitreset() {
|
||||
// Add anything new
|
||||
sh("git reset --hard")
|
||||
sh("git clean -fdx")
|
||||
summaryappend("Reset,")
|
||||
}
|
||||
|
||||
def releasegitcommit(String buildstamp) {
|
||||
sh("git commit -a -m ${buildstamp}")
|
||||
summaryappend("Commit,")
|
||||
}
|
||||
|
||||
// Determine if there has been a change by comparing the sha code in previous release meta and the build meta
|
||||
def boolean checkforchange(buildmeta, previousreleasemeta) {
|
||||
String buildsha = buildmeta.gitinfo.gitrevision
|
||||
String previoussha = previousreleasemeta.gitinfo.gitrevision
|
||||
|
||||
def boolean shachanged = (buildsha != previoussha)
|
||||
echo "buildsha: ${buildsha} previoussha: ${previoussha} changed: ${shachanged}"
|
||||
|
||||
String buildstamp = buildmeta.buildstampinfo.buildstamp
|
||||
String previousbuildstamp = previousreleasemeta.buildstampinfo.buildstamp
|
||||
|
||||
def boolean buildstampchanged = (buildstamp != previousbuildstamp)
|
||||
echo "buildstamp: ${buildstamp} previousbuildstamp: ${previousbuildstamp} changed: ${buildstampchanged}"
|
||||
|
||||
def boolean changed = (shachanged | buildstampchanged)
|
||||
echo "changed: ${changed}"
|
||||
|
||||
return changed
|
||||
}
|
||||
|
||||
def ArrayList<String> maketaglist(String buildstamp, String otherreleasetags) {
|
||||
def ArrayList<String> taglist = new ArrayList<String>()
|
||||
taglist.add(buildstamp)
|
||||
|
||||
def ArrayList<String> othertaglist = otherreleasetags.split(',')
|
||||
for (othertagitem in othertaglist) {
|
||||
if (othertagitem?.trim()) {
|
||||
taglist.add(othertagitem.trim())
|
||||
}
|
||||
}
|
||||
return taglist
|
||||
}
|
||||
|
||||
def boolean releasegittag(String postcommitshacode, String tag) {
|
||||
def boolean tagadded = false
|
||||
// Check if tag exists already
|
||||
def int gitrevparsestatus = sh(script: "git rev-parse \"${tag}\" >\"${gitrevparseoutputfile}\" 2>/dev/null", returnStatus: true)
|
||||
if (gitrevparsestatus == 0) { // Tag exists
|
||||
def existingshacode = readFile(file: gitrevparseoutputfile).trim()
|
||||
if (existingshacode != postcommitshacode) { // If the existing tag is not associated with HEAD
|
||||
// This is a problem - The tag is already at another position in git repo
|
||||
setunstable("The tag ${tag} has been used at another commit other than HEAD - You must decide what to do with it - Not good practice to delete it or move it")
|
||||
summaryappend("(${tag} - Could not add!)")
|
||||
}
|
||||
else {
|
||||
summaryappend("(${tag} - Already added)")
|
||||
}
|
||||
}
|
||||
else { // If tag does not exist already
|
||||
// Tag
|
||||
sh("git tag \"${tag}\"")
|
||||
summaryappend("(${tag})")
|
||||
tagadded = true
|
||||
}
|
||||
return tagadded
|
||||
}
|
||||
|
||||
def boolean releasegittags(String postcommitshacode, ArrayList<String> taglist) {
|
||||
boolean tagadded = false
|
||||
|
||||
summaryappend("Rel Tag ")
|
||||
for (tag in taglist) {
|
||||
if (releasegittag(postcommitshacode, tag)) {
|
||||
tagadded = true
|
||||
}
|
||||
}
|
||||
return tagadded
|
||||
}
|
||||
|
||||
def boolean sourcegittag(String shacode, String tag) {
|
||||
def boolean tagadded = false
|
||||
// Check if tag exists already
|
||||
def int gitrevparsestatus = sh(script: "git rev-parse \"${tag}\" >\"${gitrevparseoutputfile}\" 2>/dev/null", returnStatus: true)
|
||||
if (gitrevparsestatus == 0) { // Tag exists
|
||||
def existingshacode = readFile(file: gitrevparseoutputfile).trim()
|
||||
if (existingshacode != shacode) { // If the existing tag is not associated with HEAD
|
||||
// This is a problem - The tag is already at another position in git repo
|
||||
setunstable("The source tag ${tag} has been used at another commit (${existingshacode}) - You must decide what to do with it - Not good practice to delete it or move it")
|
||||
summaryappend("(${tag} - Could not add!)")
|
||||
}
|
||||
else {
|
||||
summaryappend("(${tag} - Already added)")
|
||||
}
|
||||
}
|
||||
else { // If tag does not exist already
|
||||
// Tag
|
||||
sh("git tag \"${tag}\" ${shacode}")
|
||||
summaryappend("(${tag})")
|
||||
tagadded = true
|
||||
}
|
||||
return tagadded
|
||||
}
|
||||
|
||||
def sourcegittags(String buildsha, List taglist) {
|
||||
boolean tagadded = false
|
||||
|
||||
summaryappend(",Src Tag ")
|
||||
for (tag in taglist) {
|
||||
if (sourcegittag(buildsha, tag)) {
|
||||
tagadded = true
|
||||
}
|
||||
}
|
||||
return tagadded
|
||||
}
|
||||
|
||||
def releasegitpush(String dryrunpush ) {
|
||||
if (dryrunpush == "true") {
|
||||
sh("git push -n --tags origin master")
|
||||
summaryappend(",Dry-Run-Push")
|
||||
setunstable("The artifact(s) have not been pushed/saved (\"Dry run push\" parameter/option is selected)")
|
||||
}
|
||||
else {
|
||||
sh("git push --tags origin master")
|
||||
summaryappend(",Push")
|
||||
}
|
||||
}
|
||||
|
||||
def sourcegitpush(String dryrunpush ) {
|
||||
if (dryrunpush == "true") {
|
||||
sh("git push -n --tags")
|
||||
summaryappend(",Src-Dry-Run-Push")
|
||||
setunstable("The source tag(s) have not been pushed/saved (\"Dry run push\" parameter/option is selected)")
|
||||
}
|
||||
else {
|
||||
sh("git push --tags")
|
||||
summaryappend(",Src Push")
|
||||
}
|
||||
}
|
||||
|
||||
def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String sourcerepo, String otherreleasetags, String dryrunpush) {
|
||||
summaryappend(" Git operations: ")
|
||||
def String buildstamp = buildmeta.buildstampinfo.buildstamp
|
||||
|
||||
dir(releaserepo) {
|
||||
def String precommitshacode = sh(script: "git rev-parse --verify HEAD", returnStdout: true).trim()
|
||||
echo "Pre commit sha code: ${precommitshacode}"
|
||||
|
||||
releasegitadd()
|
||||
|
||||
def boolean changed = checkforchange(buildmeta, previousreleasemeta)
|
||||
if (changed) {
|
||||
releasegitcommit(buildstamp)
|
||||
}
|
||||
else {
|
||||
releasegitreset()
|
||||
summaryappend("No-commit,")
|
||||
}
|
||||
|
||||
def String postcommitshacode = sh(script: "git rev-parse --verify HEAD", returnStdout: true).trim()
|
||||
echo "Post commit sha code: ${postcommitshacode}"
|
||||
|
||||
ArrayList<String> taglist = maketaglist(buildstamp, otherreleasetags)
|
||||
def tagadded = releasegittags(postcommitshacode, taglist)
|
||||
|
||||
if (changed || tagadded) {
|
||||
releasegitpush(dryrunpush)
|
||||
}
|
||||
}
|
||||
dir(sourcerepo) {
|
||||
def String srcbuildstamp = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}_${buildmeta.buildstampinfo.buildstamp}"
|
||||
def String buildsha = buildmeta.gitinfo.gitrevision
|
||||
|
||||
if (buildsha) {
|
||||
def ArrayList<String> srctaglist = maketaglist(srcbuildstamp, otherreleasetags)
|
||||
def tagadded = sourcegittags(buildsha, srctaglist)
|
||||
if (tagadded) {
|
||||
sourcegitpush(dryrunpush)
|
||||
}
|
||||
}
|
||||
else {
|
||||
summaryappend(",No Src ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def releasecomponent(buildinfo, String otherreleasetags, String dryrunpush) {
|
||||
def buildmeta = buildinfo.meta
|
||||
def String uniquefolder = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}"
|
||||
def String uniquefolderforrepo = "${releaserepofolder}/${uniquefolder}"
|
||||
def String uniquefoldertemp = "${tempfolder}/${uniquefolder}"
|
||||
def String uniquefolderforsourcerepo = "${sourcerepofolder}/${uniquefolder}"
|
||||
|
||||
summaryappend("${buildmeta.productinfo.productname} ${buildmeta.productinfo.subcomponentname}: ")
|
||||
def previousreleasemeta = checkoutreleaserepo(buildmeta, uniquefolderforrepo)
|
||||
|
||||
checkoutsourcerepo(buildmeta, uniquefolderforsourcerepo)
|
||||
|
||||
getcomponentartifacts(buildinfo, uniquefolderforrepo, uniquefoldertemp)
|
||||
|
||||
gitrelease(buildmeta, previousreleasemeta, uniquefolderforrepo, uniquefolderforsourcerepo, otherreleasetags, dryrunpush)
|
||||
|
||||
summaryappend("\n")
|
||||
}
|
||||
|
||||
def releasehierarchy(buildmeta, String maxdepth, String otherreleasetags, String dryrunpush) {
|
||||
int md = maxdepth.toInteger()
|
||||
resetfolders()
|
||||
preconditions()
|
||||
|
||||
// Walk the meta information to a max depth, looking for artifacts to import for release
|
||||
componentReleaseInfo = buildmeta.releasewalkerunique(md)
|
||||
|
||||
// For each component
|
||||
for (key in componentReleaseInfo.keySet()) {
|
||||
def buildinfo = componentReleaseInfo[key]
|
||||
releasecomponent(buildinfo, otherreleasetags, dryrunpush)
|
||||
}
|
||||
return [summarystring, markunstable, unstablereason]
|
||||
}
|
||||
|
||||
return this;
|
||||
12
release/registerrepo.groovy
Normal file
12
release/registerrepo.groovy
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
vc = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy")
|
||||
|
||||
// Prove the existence of the release repo - otherwise there is a large wait to cycle the build to correct the meta data
|
||||
def registerrepo(meta, String releaserepo) {
|
||||
if (releaserepo?.trim()) {
|
||||
vc.gitCheckout(releaserepo, "origin/master", "tmp/releaserepo")
|
||||
}
|
||||
meta.releaseinfo.set(releaserepo)
|
||||
}
|
||||
|
||||
return this;
|
||||
90
release/release.groovy
Normal file
90
release/release.groovy
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
pipeline {
|
||||
agent { label "${AGENT_LABEL}" }
|
||||
stages {
|
||||
stage('Initial setup') {
|
||||
steps {
|
||||
script {
|
||||
autobuilderscript = load("${WORKSPACE}/autobuild/Common_scripts/autobuilder.groovy")
|
||||
meta = autobuilderscript.start(this, PRODUCT_NAME, SUBCOMPONENT_NAME, JIRA_KEY, RELEASE_REPO)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Clean exports') {
|
||||
steps {
|
||||
script {
|
||||
cleanfolders = [
|
||||
"${WORKSPACE}/build_artifacts",
|
||||
]
|
||||
cleaner = load("${autobuilder.commonscripts()}/clean/clean.groovy")
|
||||
cleaner.clean(cleanfolders)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Get build artifact meta') {
|
||||
steps {
|
||||
script {
|
||||
BUILD_ARTIFACTS = "${WORKSPACE}/build_artifacts"
|
||||
copyArtifacts(
|
||||
filter: 'meta/**',
|
||||
projectName: BUILD_JOB,
|
||||
selector: [
|
||||
$class: 'ParameterizedBuildSelector',
|
||||
parameterName: BUILD_JOB_SELECTOR
|
||||
],
|
||||
target: BUILD_ARTIFACTS
|
||||
)
|
||||
def mfs = autobuilderscript.getmetafolderscript()
|
||||
buildmeta = mfs.metafromfolder(BUILD_ARTIFACTS)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Release components') {
|
||||
steps {
|
||||
script {
|
||||
def releaser = load("${autobuilder.commonscripts()}/release/do.groovy")
|
||||
// Place the top level build stamp on all
|
||||
def topleveltag = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}_${buildmeta.buildstampinfo.buildstamp}"
|
||||
OTHER_RELEASE_TAGS = "${topleveltag},${OTHER_RELEASE_TAGS}"
|
||||
(summarystring, markunstable, unstablereason) = releaser.releasehierarchy(buildmeta, MAX_META_DEPTH, OTHER_RELEASE_TAGS, DRY_RUN_PUSH)
|
||||
if (markunstable) {
|
||||
env.unstablereason = unstablereason
|
||||
currentBuild.result = 'UNSTABLE'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Archiving artifacts') {
|
||||
steps {
|
||||
script {
|
||||
def artifactlist = meta.generateartifacts()
|
||||
archiveArtifacts "summary/**,${artifactlist}"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Summarise') {
|
||||
steps {
|
||||
script {
|
||||
echo "Summary:\n${summarystring}\n"
|
||||
if (env.unstablereason) {
|
||||
echo "Instability reason: ${env.unstablereason}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
echo 'Post-build'
|
||||
}
|
||||
failure {
|
||||
echo 'Failed build'
|
||||
}
|
||||
unstable {
|
||||
echo 'Unstable build'
|
||||
}
|
||||
success {
|
||||
echo 'Succeeded build'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,12 +1,25 @@
|
|||
clh = load("${COMMON_SCRIPTS}/commandline/commandline.gsh")
|
||||
import hudson.plugins.git.*
|
||||
import hudson.plugins.git.extensions.*
|
||||
import hudson.plugins.git.extensions.impl.*
|
||||
|
||||
clh = load("${autobuilder.commonscripts()}/commandline/commandline.groovy")
|
||||
|
||||
String getGitInfo(String workingSetRootPath) {
|
||||
dir(workingSetRootPath) {
|
||||
return clh.getCommandOutput('git log -1 --format=oneline')
|
||||
return clh.getCommandOutput('git rev-parse HEAD')
|
||||
}
|
||||
}
|
||||
|
||||
def gitCheckout(String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true) {
|
||||
@NonCPS
|
||||
def SparseCheckoutPaths sparsecheckoutconfig(ArrayList<String> paths) {
|
||||
ArrayList<SparseCheckoutPath> sparsecheckoutpaths = new ArrayList<SparseCheckoutPath>()
|
||||
for (path in paths) {
|
||||
sparsecheckoutpaths.add(new SparseCheckoutPath(path))
|
||||
}
|
||||
return new SparseCheckoutPaths(sparsecheckoutpaths)
|
||||
}
|
||||
|
||||
def gitCheckout(String gitURL, String revision, String targetDir, String repoRoot = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
reporootenv = env.REPO_ROOT
|
||||
if (reporootenv != null && repoRoot != "") {
|
||||
reporootpath = "${reporootenv.trim()}/${repoRoot}"
|
||||
|
|
@ -28,7 +41,8 @@ def gitCheckout(String gitURL, String revision, String targetDir, String repoRoo
|
|||
[$class: 'CleanBeforeCheckout'],
|
||||
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: reporootpath, shallow: shallowClone, timeout: 120],
|
||||
[$class: 'CheckoutOption', timeout: 120],
|
||||
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir]
|
||||
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir],
|
||||
sparsecheckoutconfig(sparseitemlist)
|
||||
],
|
||||
submoduleCfg: [],
|
||||
])
|
||||
23
versionnumbering/do.groovy
Normal file
23
versionnumbering/do.groovy
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
def stamp(convertdetails) {
|
||||
for (convertdetail in convertdetails) {
|
||||
def filetoconvert = convertdetail[0]
|
||||
def pattern = convertdetail[1]
|
||||
def replacement = convertdetail[2]
|
||||
//echo "Converting any instances of pattern: ${pattern} with replacement: ${replacement} in file: ${filetoconvert}"
|
||||
def stampscript = "${autobuilder.commonscripts()}/versionstamping/versionstamper.py"
|
||||
//echo "Using python: ${PYTHON} and script: ${stampscript}"
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
"${PYTHON}" -u "${stampscript}" -f "${filetoconvert}" -p "${pattern}" -s "${replacement}"
|
||||
"""
|
||||
}
|
||||
else {
|
||||
bat """
|
||||
"${PYTHON}" -u "${stampscript}" -f "${filetoconvert}" -p "${pattern}" -s "${replacement}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
150
versionnumbering/generate.groovy
Normal file
150
versionnumbering/generate.groovy
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
|
||||
def int maxversionnumber() {
|
||||
def int MAXVERSIONNUMBER = 65535
|
||||
return MAXVERSIONNUMBER
|
||||
}
|
||||
|
||||
def getGitRevision(String gitrootpath, int basebuildnumber) {
|
||||
def int adjustedchangecount
|
||||
def String gitrevision
|
||||
def String remoteinfo
|
||||
def String remoteurl
|
||||
dir( gitrootpath) {
|
||||
def int changecount = 0
|
||||
if (isUnix()) {
|
||||
changecount = sh(returnStdout: true, script: "git rev-list HEAD --count").trim().toInteger()
|
||||
}
|
||||
else {
|
||||
changecount = bat(returnStdout: true, script: "@git rev-list HEAD --count").trim().toInteger()
|
||||
}
|
||||
echo "Change count: ${changecount}"
|
||||
adjustedchangecount = ((changecount + basebuildnumber).abs()) % (maxversionnumber() + 1)
|
||||
echo "Adjusted change count: ${adjustedchangecount}"
|
||||
if (isUnix()) {
|
||||
gitrevision = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
|
||||
}
|
||||
else {
|
||||
gitrevision = bat(returnStdout: true, script: "@git rev-parse HEAD").trim()
|
||||
}
|
||||
echo "Revision: ${gitrevision}"
|
||||
if (isUnix()) {
|
||||
remoteinfo = sh(returnStdout: true, script: "git remote show origin").trim()
|
||||
}
|
||||
else {
|
||||
remoteinfo = bat(returnStdout: true, script: "@git remote show origin").trim()
|
||||
}
|
||||
echo "Remote info: ${remoteinfo}"
|
||||
if (isUnix()) {
|
||||
remoteurl = sh(returnStdout: true, script: "git config --get remote.origin.url").trim()
|
||||
}
|
||||
else {
|
||||
remoteurl = bat(returnStdout: true, script: "@git config --get remote.origin.url").trim()
|
||||
}
|
||||
echo "Remote URL: ${remoteurl}"
|
||||
}
|
||||
return [adjustedchangecount, gitrevision, remoteinfo, remoteurl]
|
||||
}
|
||||
|
||||
// Handle:
|
||||
// origin/master
|
||||
// origin/2.0.x
|
||||
def getVersionPrefix(String sourcebranch) {
|
||||
echo "Determining version number prefix from source branch name: ${sourcebranch}"
|
||||
sourcebranch = sourcebranch.toLowerCase()
|
||||
|
||||
def defaultversionprefix = "1.30000.0."
|
||||
def splits = sourcebranch.split('/')
|
||||
if (splits.size() < 1) {
|
||||
echo "Source branch name is invalid. Defaulting to: ${defaultversionprefix}"
|
||||
return defaultversionprefix
|
||||
}
|
||||
|
||||
def mastertypeversionprefix = "1.20000.0."
|
||||
sourcebranch = splits.last()
|
||||
if (sourcebranch.toLowerCase().find("master") != null) {
|
||||
echo "Source branch name has 'master' in it. Defaulting to: ${mastertypeversionprefix}"
|
||||
return mastertypeversionprefix
|
||||
}
|
||||
|
||||
def splits2 = sourcebranch.split('\\.')
|
||||
if (splits2.size() < 1) {
|
||||
def thirdpartyversionprefix = "1.25000.0."
|
||||
echo "Source branch name has no dots in it (eg. 1.9.2). Defaulting to: ${thirdpartyversionprefix}"
|
||||
return thirdpartyversionprefix
|
||||
}
|
||||
|
||||
for (split in splits2) {
|
||||
if (split == "x") {
|
||||
echo "Source branch name has '.x' or 'x.' in it. Defaulting to: ${mastertypeversionprefix}"
|
||||
return mastertypeversionprefix
|
||||
}
|
||||
}
|
||||
|
||||
def integerstrings = sourcebranch.findAll(/\d+/)
|
||||
def integers = []
|
||||
for (integerstring in integerstrings) {
|
||||
int integer = integerstring.toInteger()
|
||||
integer = integer % (maxversionnumber() + 1)
|
||||
integers.add(integer)
|
||||
}
|
||||
|
||||
def versionprefix = ""
|
||||
if (integers.size() < 1) {
|
||||
echo "This source branch name has no numbers in its name so defaulting to: ${defaultversionprefix}"
|
||||
versionprefix = defaultversionprefix
|
||||
}
|
||||
else {
|
||||
def int integernumbercount = 0
|
||||
for (integer in integers) {
|
||||
versionprefix += integer + "."
|
||||
integernumbercount += 1
|
||||
if (integernumbercount > 2) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (integernumbercount == 0) {
|
||||
echo "No leading numbers were found in source branch name so defaulting to: ${defaultversionprefix}"
|
||||
versionprefix = defaultversionprefix
|
||||
}
|
||||
else if (integernumbercount == 1) {
|
||||
versionprefix += "0.0."
|
||||
}
|
||||
else if (integernumbercount == 2) {
|
||||
versionprefix += "0."
|
||||
}
|
||||
}
|
||||
echo "Determined version prefix to be: ${versionprefix}"
|
||||
return versionprefix
|
||||
}
|
||||
|
||||
String generate(meta, String sourcerevision, String sourcepath, int basebuildnumber = 1000) {
|
||||
def int gitrevisioncount
|
||||
def String gitrevision
|
||||
def String remoteinfo
|
||||
def String remoteurl
|
||||
|
||||
(gitrevisioncount, gitrevision, remoteinfo, remoteurl) = getGitRevision(sourcepath, basebuildnumber)
|
||||
|
||||
def versionprefix = getVersionPrefix(sourcerevision)
|
||||
|
||||
def buildstamp = versionprefix + gitrevisioncount.toString()
|
||||
echo "Build stamp is: ${buildstamp}"
|
||||
|
||||
meta.gitinfo.set(sourcepath, sourcerevision, gitrevision, remoteurl, remoteinfo)
|
||||
meta.buildstampinfo.set(versionprefix, gitrevisioncount, buildstamp)
|
||||
|
||||
return buildstamp
|
||||
}
|
||||
|
||||
String generate(meta, String sourcerevision, String sourcepath, String basebuildnumber) {
|
||||
def int bbn = basebuildnumber.trim().toInteger()
|
||||
return generate(meta, sourcerevision, sourcepath, bbn)
|
||||
}
|
||||
|
||||
int incrementrevision(int current, int increment) {
|
||||
def int newrevision = (current + increment) % (maxversionnumber() + 1)
|
||||
echo "Current revision: ${current} Increment: ${increment} New revision: ${newrevision}"
|
||||
return newrevision
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
|
||||
def currentContents(file, newline = "\n", defaultContents = "") {
|
||||
if (fileExists("${file}")) {
|
||||
contents = readFile(file: "${file}").trim() + newline
|
||||
}
|
||||
else {
|
||||
contents = defaultContents
|
||||
}
|
||||
return contents
|
||||
}
|
||||
|
||||
def mergemeta(versionFolder, outputFolder) {
|
||||
echo "Merging meta data from folder: ${versionFolder} to ${outputFolder}"
|
||||
|
||||
differencesFile = "${versionFolder}/differences.txt"
|
||||
newContents = readFile file: "${differencesFile}"
|
||||
metadifferencesFile = "${outputFolder}/differences.txt"
|
||||
writeFile file: "${metadifferencesFile}", text: currentContents(metadifferencesFile) + newContents
|
||||
|
||||
buildStampFile = "${versionFolder}/buildstamps.txt"
|
||||
buildStampFileContents = readFile("${buildStampFile}").trim()
|
||||
metabuildStampFile = "${outputFolder}/buildstamps.txt"
|
||||
writeFile file: "${metabuildStampFile}", text: currentContents(metabuildStampFile) + buildStampFileContents
|
||||
|
||||
if (fileExists("${versionFolder}/revision.txt")) {
|
||||
revision = readFile("${versionFolder}/revision.txt").trim()
|
||||
intrevision = revision.toInteger()
|
||||
echo "Revision read in: ${intrevision}"
|
||||
}
|
||||
else {
|
||||
intrevision = 1
|
||||
}
|
||||
|
||||
return intrevision
|
||||
}
|
||||
|
||||
def appendcomponentinfo(versionFolder, outputFolder) {
|
||||
echo "Appending component version data from folder: ${versionFolder} to ${outputFolder}"
|
||||
|
||||
differencesFile = "${versionFolder}/differences.txt"
|
||||
if (fileExists("${differencesFile}")) {
|
||||
newContents = readFile file: "${differencesFile}"
|
||||
metadifferencesFile = "${outputFolder}/differences.txt"
|
||||
writeFile file: "${metadifferencesFile}", text: currentContents(metadifferencesFile) + "${differencesFile}:\n" + newContents
|
||||
}
|
||||
|
||||
buildStampFile = "${versionFolder}/buildstamp.txt"
|
||||
buildStampFileContents = readFile("${buildStampFile}").trim()
|
||||
|
||||
remoteurlFile = "${versionFolder}/remoteurl.txt"
|
||||
remoteurlFileContents = currentContents(remoteurlFile, "", 'Unknown').trim()
|
||||
|
||||
gitRevisionFile = "${versionFolder}/gitrevision.txt"
|
||||
gitRevisionFileContents = readFile("${gitRevisionFile}").trim()
|
||||
|
||||
releaseJobNameFile = "${versionFolder}/releasejobname.txt"
|
||||
releaseJobNameContents = currentContents("${releaseJobNameFile}", "", "-").trim()
|
||||
|
||||
metabuildStampFile = "${outputFolder}/buildstamps.txt"
|
||||
writeFile file: "${metabuildStampFile}", text: currentContents(metabuildStampFile) + "${versionFolder}" + ":" + buildStampFileContents + "," + remoteurlFileContents + "," + gitRevisionFileContents + "," + releaseJobNameContents
|
||||
revision = readFile("${versionFolder}/revision.txt").trim()
|
||||
intrevision = revision.toInteger()
|
||||
echo "Revision read in: ${intrevision}"
|
||||
|
||||
return intrevision
|
||||
}
|
||||
|
||||
// Each version folder should have been created using version creation scripts in this Common_scripts folder
|
||||
// as their are well-known files in each folder
|
||||
def combineSubjobVersions(versionLabelPrefix, versionFolderList, outputFolder = "${WORKSPACE}/metaversion") {
|
||||
totalrevision = 0
|
||||
dir("${outputFolder}") {
|
||||
deleteDir()
|
||||
}
|
||||
for (versionFolder in versionFolderList) {
|
||||
echo "Inspecting folder: ${versionFolder}"
|
||||
metaversionsignaturefile = "${versionFolder}/metaversion.txt"
|
||||
// If the sub project is a meta job
|
||||
if (fileExists("${metaversionsignaturefile}")) {
|
||||
intrevision = mergemeta("${versionFolder}", outputFolder)
|
||||
}
|
||||
else {
|
||||
intrevision = appendcomponentinfo("${versionFolder}", outputFolder)
|
||||
}
|
||||
totalrevision += intrevision
|
||||
}
|
||||
echo "Accumulated revision is: ${totalrevision}"
|
||||
writeFile file: "${outputFolder}/metaversion.txt", text: versionLabelPrefix + ((versionLabelPrefix.endsWith(".")) ? "" : ".") + totalrevision.toString()
|
||||
writeFile(file: "${outputFolder}/revision.txt", text: totalrevision.toString())
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -1,252 +0,0 @@
|
|||
# encoding: utf-8
|
||||
'''
|
||||
versionnumbering -- shortdesc
|
||||
|
||||
versionnumbering generates a version folder with a common set of version information files in it
|
||||
|
||||
@author: dan
|
||||
|
||||
@copyright: 2017 Global Inkjet Systems Ltd. All rights reserved.
|
||||
'''
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
import re
|
||||
import datetime
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from argparse import RawDescriptionHelpFormatter
|
||||
|
||||
__all__ = []
|
||||
__version__ = 0.1
|
||||
__date__ = '2017-11-29'
|
||||
__updated__ = '2017-11-29'
|
||||
|
||||
gitExecutable = os.getenv("GIT_EXECUTABLE", default="git")
|
||||
slaveMachine = os.getenv("NODE_NAME", default="-")
|
||||
MAXVERSIONNUMBER = 65535
|
||||
|
||||
def resetFolder(versionfolder):
|
||||
print("Removing folders and contents of: {0}".format(versionfolder))
|
||||
try:
|
||||
shutil.rmtree(versionfolder)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
print("Creating folder: {0}".format(versionfolder))
|
||||
os.makedirs(versionfolder)
|
||||
|
||||
def getGitRevision(gitrootpath, basenumber):
|
||||
cwd = os.getcwd()
|
||||
|
||||
path = os.path.expanduser(gitrootpath)
|
||||
print("Changing current working directory to: {0}".format(path))
|
||||
os.chdir(path)
|
||||
|
||||
print("Determining revision info using git command: {0}".format(gitExecutable))
|
||||
completed = subprocess.run([gitExecutable, "rev-list", "HEAD", "--count"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
changecount = completed.stdout.decode("utf-8").strip()
|
||||
print("Change count: {0}".format(changecount))
|
||||
adjustedchangecount = int((int(changecount) + int(basenumber)) % (MAXVERSIONNUMBER + 1))
|
||||
print("Adjusted change count: {0}".format(adjustedchangecount))
|
||||
|
||||
print("Determining current revision info using git command: {0}".format(gitExecutable))
|
||||
completed = subprocess.run([gitExecutable, "rev-parse", "HEAD"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
revision = completed.stdout.decode("utf-8").strip()
|
||||
print("Revision: {0}".format(revision))
|
||||
|
||||
print("Determining remote info using git command: {0}".format(gitExecutable))
|
||||
completed = subprocess.run([gitExecutable, "remote", "show", "origin"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
remoteinfo = completed.stdout.decode("utf-8")
|
||||
print("Remote info: {0}".format(remoteinfo))
|
||||
|
||||
print("Determining remote url using git command: {0}".format(gitExecutable))
|
||||
completed = subprocess.run([gitExecutable, "remote", "get-url", "--push", "origin"], stdout=subprocess.PIPE)
|
||||
print("Command {0} returned: {1}".format(completed.args, completed.returncode))
|
||||
remoteurl = completed.stdout.decode("utf-8")
|
||||
print("Remote info: {0}".format(remoteurl))
|
||||
|
||||
os.chdir(cwd)
|
||||
print("Restored current working directory to: {0}".format(cwd))
|
||||
|
||||
return (adjustedchangecount, revision, remoteinfo, remoteurl)
|
||||
|
||||
# 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."
|
||||
thirdpartyversionprefix = "1.25000.0."
|
||||
splits = sourcebranch.split('/')
|
||||
if len(splits) < 1:
|
||||
print("Source branch name is invalid. Defaulting to: {0}".format(defaultversionprefix))
|
||||
return defaultversionprefix
|
||||
|
||||
sourcebranch = splits[-1]
|
||||
|
||||
if sourcebranch.lower().find("master") != -1: # Special case
|
||||
return mastertypeversionprefix
|
||||
|
||||
splits2 = re.split(r'(\d+)', sourcebranch)
|
||||
splits = []
|
||||
hasdot = False
|
||||
for split in splits2:
|
||||
if split.isdigit():
|
||||
splits.append(split)
|
||||
if split == ".":
|
||||
hasdot = True
|
||||
|
||||
if not hasdot:
|
||||
print("Source branch name has not dots in it (eg. 1.9.2). Defaulting to: {0}".format(thirdpartyversionprefix))
|
||||
return thirdpartyversionprefix
|
||||
|
||||
versionprefix = ""
|
||||
if len(splits) < 1:
|
||||
print("This source branch name has no numbers in its name so defaulting to: {0}".format(defaultversionprefix))
|
||||
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
|
||||
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, gitrevisioncount, gitrevision, remoteinfo, remoteurl, buildnumber, buildstamp, releasejobname):
|
||||
with open(os.path.join(versionfolder, "buildjobname.txt"), 'w') as f:
|
||||
f.write(buildjobname)
|
||||
|
||||
with open(os.path.join(versionfolder, "prefix.txt"), 'w') as f:
|
||||
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:
|
||||
f.write(remoteinfo)
|
||||
|
||||
with open(os.path.join(versionfolder, "remoteurl.txt"), 'w') as f:
|
||||
f.write(remoteurl)
|
||||
|
||||
with open(os.path.join(versionfolder, "buildnumber.txt"), 'w') as f:
|
||||
f.write(buildnumber)
|
||||
|
||||
with open(os.path.join(versionfolder, "buildstamp.txt"), 'w') as f:
|
||||
f.write(buildstamp)
|
||||
|
||||
buildstampcommasep = buildstamp.replace(".", ",")
|
||||
with open(os.path.join(versionfolder, "buildstampcommasep.txt"), 'w') as f:
|
||||
f.write(buildstampcommasep)
|
||||
|
||||
with open(os.path.join(versionfolder, "buildmachine.txt"), 'w') as f:
|
||||
f.write(slaveMachine)
|
||||
|
||||
with open(os.path.join(versionfolder, "builddate.txt"), 'w') as f:
|
||||
f.write(str(datetime.datetime.now()))
|
||||
|
||||
with open(os.path.join(versionfolder, "releasejobname.txt"), 'w') as f:
|
||||
f.write(releasejobname)
|
||||
|
||||
def main(argv=None): # IGNORE:C0111
|
||||
'''Command line options.'''
|
||||
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
else:
|
||||
sys.argv.extend(argv)
|
||||
|
||||
program_name = os.path.basename(sys.argv[0])
|
||||
program_version = "v%s" % __version__
|
||||
program_build_date = str(__updated__)
|
||||
program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
|
||||
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
|
||||
program_license = '''%s
|
||||
|
||||
Created by dan on %s.
|
||||
Copyright 2017 Global Inkjet Systems Ltd. All rights reserved.
|
||||
|
||||
Distributed on an "AS IS" basis without warranties
|
||||
or conditions of any kind, either express or implied.
|
||||
|
||||
USAGE
|
||||
''' % (program_shortdesc, str(__date__))
|
||||
|
||||
try:
|
||||
# Setup argument parser
|
||||
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
|
||||
parser.add_argument("-s", "--sourcebranch", dest="sourcebranch", action="store", default="origin/master", help="source branch name to discover version number [default: %(default)s]")
|
||||
parser.add_argument("-v", "--versionfolder", dest="versionfolder", action="store", default="version", help="version folder to be created [default: %(default)s]")
|
||||
parser.add_argument("-g", "--gitroot", dest="gitrootfolder", action="store", default="GitRepository", help="root path of source files [default: %(default)s]")
|
||||
parser.add_argument("-b", "--baseversionnumber", dest="baseversionnumber", action="store", default=int(1000), help="base git version number [default: %(default)s]")
|
||||
parser.add_argument("-j", "--buildjobname", dest="buildjobname", action="store", default="-", help="build job name [default: %(default)s]")
|
||||
parser.add_argument("-n", "--buildnumber", dest="buildnumber", action="store", default="1", help="build number [default: %(default)s]")
|
||||
parser.add_argument("-r", "--releasejobname", dest="releasejobname", action="store", default="-", help="release-to-git build job name [default: %(default)s]")
|
||||
|
||||
# Process arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
sourcebranch = args.sourcebranch
|
||||
versionfolder = args.versionfolder
|
||||
gitrootfolder = args.gitrootfolder
|
||||
baseversionnumber = args.baseversionnumber
|
||||
buildjobname = args.buildjobname
|
||||
buildnumber = args.buildnumber
|
||||
releasejobname = args.releasejobname
|
||||
|
||||
print("Source branch:", sourcebranch, "version folder:", versionfolder, "Git root:", gitrootfolder)
|
||||
print("Base version number:", baseversionnumber, "Build job name:", buildjobname, "Build number:", buildnumber, "Release job name:", releasejobname)
|
||||
|
||||
resetFolder(versionfolder)
|
||||
|
||||
(gitrevisioncount, gitrevision, remoteinfo, remoteurl) = getGitRevision(gitrootfolder, baseversionnumber)
|
||||
|
||||
versionprefix = getVersionPrefix(sourcebranch)
|
||||
|
||||
buildstamp = versionprefix + str(gitrevisioncount)
|
||||
print("Build stamp is: {0}".format(buildstamp))
|
||||
|
||||
writeversionfiles(versionfolder, buildjobname, versionprefix, gitrevisioncount, gitrevision, remoteinfo, remoteurl, buildnumber, buildstamp, releasejobname)
|
||||
|
||||
return 0
|
||||
except Exception as e:
|
||||
print("Error while creating version info:", e.__repr__())
|
||||
return 1
|
||||
|
||||
except Exception as e:
|
||||
indent = len(program_name) * " "
|
||||
print(program_name + ": " + repr(e) + "\n")
|
||||
print(indent + " for help use --help")
|
||||
return 2
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue