Merge commit 'fb25a6b30b' into common_script_update

This commit is contained in:
Damian Smith 2019-01-28 10:00:44 +00:00
commit da41d5a014
8 changed files with 135 additions and 46 deletions

View file

@ -3,6 +3,8 @@ def comparefiles(importedjsonfile, currentjsonfile) {
env.CURRENT_JSON="${currentjsonfile}"
if (isUnix()) {
sh """
which jq
if [ \$? -ne 0 ]; then exit 1; fi
# jq -S sorts json output
diff -c <(jq -S . "${IMPORTED_JSON}") <(jq -S . "${CURRENT_JSON}")
"""

View file

@ -7,7 +7,7 @@ def Map artifactsImporter(meta, artifactDetails, installerDetails) {
def artifactKey = installerDetails.get(installer)[0]
(sourceProject, sourceselector, destFolder, toCopy, notToCopy, binariesFolders) = artifactDetails.get(artifactKey)
if (artifactFetched.get(artifactKey) == null) {
def importmeta = importer.artifactimport(meta, sourceProject, sourceselector, destFolder, toCopy, notToCopy, true)
def importmeta = importer.artifactimport(meta, sourceProject, sourceselector, destFolder, toCopy, notToCopy)
artifactFetched.put(artifactKey, importmeta)
}
}

View file

@ -161,7 +161,7 @@ class BuildStampInfo extends GISJsonSerialised {
int revision
String buildstamp
BuildStampInfo(script, buildstampprefix = "", revision = 0, buildstamp = "") {
BuildStampInfo(script, buildstampprefix = "1.30000.0.", revision = 0, buildstamp = "1.30000.0.0") {
super(script)
this.buildstampprefix = buildstampprefix
this.revision = revision
@ -188,6 +188,17 @@ class BuildStampInfo extends GISJsonSerialised {
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']
@ -647,17 +658,40 @@ class MetaInfo extends GISJsonSerialised {
return releasemetacollection
}
String componentidentifier() {
return productinfo.productname + "_" + productinfo.subcomponentname
}
String componentversionuniqueidentifier() {
return productinfo.productname + "_" + productinfo.subcomponentname + "_" + buildstampinfo.buildstamp
}
Map<String, RelatedMetaInfo> releasewalkerunique(int maxdepth, String startpath = "") {
Map<String, RelatedMetaInfo> releasemetauniquecollection = new LinkedHashMap<String, RelatedMetaInfo>()
ArrayList<RelatedMetaInfo> releasemetacollection = new ArrayList<RelatedMetaInfo>()
def ArrayList<RelatedMetaInfo> releasemetacollection = new ArrayList<RelatedMetaInfo>()
releasemetacollection = releasewalkerp(maxdepth, releasemetacollection, startpath)
def Map<String, RelatedMetaInfo> releasemetauniquecollection = new LinkedHashMap<String, RelatedMetaInfo>()
for (relatedmetainfo in releasemetacollection) {
String uniquestring = relatedmetainfo.meta.productinfo.productname + "_" + relatedmetainfo.meta.productinfo.subcomponentname
def String uniquestring = relatedmetainfo.meta.componentidentifier()
releasemetauniquecollection.put(uniquestring, relatedmetainfo)
}
return releasemetauniquecollection
}
Map<String, RelatedMetaInfo> releasewalkerversionunique(int maxdepth, String startpath = "") {
ArrayList<RelatedMetaInfo> releasemetacollection = new ArrayList<RelatedMetaInfo>()
releasemetacollection = releasewalkerp(maxdepth, releasemetacollection, startpath)
def Map<String, RelatedMetaInfo> releasemetaversionuniquecollection = new LinkedHashMap<String, RelatedMetaInfo>()
for (relatedmetainfo in releasemetacollection) {
def String uniquestring = relatedmetainfo.meta.componentversionuniqueidentifier()
releasemetaversionuniquecollection.put(uniquestring, relatedmetainfo)
}
return releasemetaversionuniquecollection
}
MetaInfo getNewMetaObject(script) {
return new MetaInfo(script)
}

View file

@ -44,7 +44,7 @@ def getcomponentartifacts(releaseinfo, String repofolder, String tempfolder) {
def releasemeta = releaseinfo.meta
def String componentURL = releasemeta.releaseinfo.releaserepoURL
def String revision = "refs/tags/${releasemeta.buildstampinfo.buildstamp}"
def String revision = "refs/tags/${releasemeta.buildstampinfo.buildstamp}_${releasemeta.jenkinsbuildinfo.buildnumber}"
def publishableitems = releasemeta.publishableinfo
def ArrayList<String> publishablePaths = new ArrayList<String>()
if (publishableitems.size() > 0) {
@ -107,12 +107,18 @@ def publishhierarchy(releasemeta, String customer, String softwarerelease, Strin
resetfolders()
preconditions()
// Walk the meta information to a max depth, looking for artifacts to import for release
componentReleaseInfo = releasemeta.releasewalkerunique(md)
// Walk the meta information to a max depth, looking for artifacts to publish
def componentReleaseInfoVersionUnique = releasemeta.releasewalkerversionunique(md)
// For each component
for (key in componentReleaseInfo.keySet()) {
def releaseinfo = componentReleaseInfo[key]
echo "Version unique components:"
def String versionuniquecomponent = ""
for (key in componentReleaseInfoVersionUnique.keySet()) {
versionuniquecomponent += "${key}\n"
}
echo versionuniquecomponent
for (key in componentReleaseInfoVersionUnique.keySet()) {
def releaseinfo = componentReleaseInfoVersionUnique[key]
recallcomponent(releaseinfo, softwarerelease)
}
stripgithistory()

View file

@ -44,7 +44,6 @@ pipeline {
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

View file

@ -32,7 +32,8 @@ def preconditions() {
def setunstable(String reason) {
markunstable = true
unstablereason = reason
unstablereason += reason + "\n"
echo "Marked build as unstable: Reason: ${reason}"
}
def summaryappend(String summary) {
@ -68,23 +69,25 @@ def checkoutreleaserepo(buildmeta, String checkoutfolder) {
def checkoutsourcerepo(buildmeta, String checkoutfolder) {
def String sourcerepo = buildmeta.gitinfo.remoteurl
// 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
"""
)
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}")
else {
dir(sourcerepofolder) {
sh("git clone ${sourcerepo} ${checkoutfolder}")
}
}
}
}
@ -155,14 +158,15 @@ def boolean checkforchange(buildmeta, previousreleasemeta) {
return changed
}
def ArrayList<String> maketaglist(String buildstamp, String otherreleasetags) {
def ArrayList<String> maketaglist(buildmeta, 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())
def componentothertagitem = "${othertagitem.trim()}_${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}"
taglist.add(componentothertagitem)
}
}
return taglist
@ -267,6 +271,7 @@ def sourcegitpush(String dryrunpush ) {
def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String sourcerepo, String otherreleasetags, String dryrunpush) {
summaryappend(" Git operations: ")
def String buildstamp = buildmeta.buildstampinfo.buildstamp
def String buildstamptag = "${buildstamp}_${buildmeta.jenkinsbuildinfo.buildnumber}"
dir(releaserepo) {
def String precommitshacode = sh(script: "git rev-parse --verify HEAD", returnStdout: true).trim()
@ -276,7 +281,7 @@ def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String source
def boolean changed = checkforchange(buildmeta, previousreleasemeta)
if (changed) {
releasegitcommit(buildstamp)
releasegitcommit(buildstamptag)
}
else {
releasegitreset()
@ -286,7 +291,7 @@ def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String source
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)
ArrayList<String> taglist = maketaglist(buildmeta, buildstamptag, otherreleasetags)
def tagadded = releasegittags(postcommitshacode, taglist)
if (changed || tagadded) {
@ -294,13 +299,18 @@ def gitrelease(buildmeta, previousreleasemeta, String releaserepo, String source
}
}
dir(sourcerepo) {
def String srcbuildstamp = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}_${buildmeta.buildstampinfo.buildstamp}"
def String srcbuildstamptag = "${buildmeta.productinfo.productname}_${buildmeta.productinfo.subcomponentname}_${buildstamptag}"
def String buildsha = buildmeta.gitinfo.gitrevision
def ArrayList<String> srctaglist = maketaglist(srcbuildstamp, otherreleasetags)
def tagadded = sourcegittags(buildsha, srctaglist)
if (tagadded) {
sourcegitpush(dryrunpush)
if (buildsha) {
def ArrayList<String> srctaglist = maketaglist(buildmeta, srcbuildstamptag, otherreleasetags)
def tagadded = sourcegittags(buildsha, srctaglist)
if (tagadded) {
sourcegitpush(dryrunpush)
}
}
else {
summaryappend(",No Src ")
}
}
}
@ -329,14 +339,42 @@ def releasehierarchy(buildmeta, String maxdepth, String otherreleasetags, String
resetfolders()
preconditions()
// Walk the meta information to a max depth, looking for artifacts to import for release
componentReleaseInfo = buildmeta.releasewalkerunique(md)
// Walk the meta information to a max depth, looking for components to release
def componentReleaseInfo = buildmeta.releasewalkerunique(md)
echo "Unique components:"
def String versioncomponent = ""
for (key in componentReleaseInfo.keySet()) {
versioncomponent += "${key}\n"
}
echo versioncomponent
// Walk the meta information to a max depth, looking for components to release
def componentReleaseInfoVersionUnique = buildmeta.releasewalkerversionunique(md)
echo "Version unique components:"
def String versionuniquecomponent = ""
for (key in componentReleaseInfoVersionUnique.keySet()) {
versionuniquecomponent += "${key}\n"
}
echo versionuniquecomponent
if (DO_INTEGRITY_CHECK == "true") {
if (componentReleaseInfo.size() != componentReleaseInfoVersionUnique.size()) {
error "There are 2 or more versions of the same component being used in this hierarchy: Is this correct?"
}
}
def toplevelid = buildmeta.componentidentifier()
// For each component
for (key in componentReleaseInfo.keySet()) {
def buildinfo = componentReleaseInfo[key]
releasecomponent(buildinfo, otherreleasetags, dryrunpush)
if (toplevelid != key) {
releasecomponent(buildinfo, otherreleasetags, dryrunpush)
}
}
// Do the top level last
def toplevelbuildinfo = componentReleaseInfo[toplevelid]
releasecomponent(toplevelbuildinfo, otherreleasetags, dryrunpush)
return [summarystring, markunstable, unstablereason]
}

View file

@ -42,6 +42,9 @@ pipeline {
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}_${buildmeta.jenkinsbuildinfo.buildnumber}"
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

View file

@ -4,6 +4,12 @@ def int maxversionnumber() {
return MAXVERSIONNUMBER
}
int incrementrevision(int current, int increment) {
def int newrevision = (current + increment) % (maxversionnumber() + 1)
echo "Current revision: ${current} Increment: ${increment} New revision: ${newrevision}"
return newrevision
}
def getGitRevision(String gitrootpath, int basebuildnumber) {
def int adjustedchangecount
def String gitrevision
@ -18,7 +24,9 @@ def getGitRevision(String gitrootpath, int basebuildnumber) {
changecount = bat(returnStdout: true, script: "@git rev-list HEAD --count").trim().toInteger()
}
echo "Change count: ${changecount}"
adjustedchangecount = (changecount + basebuildnumber) % (maxversionnumber() + 1)
def int mvnp1 = maxversionnumber() + 1
basebuildnumber = (basebuildnumber < 0) ? mvnp1 - (basebuildnumber.abs() % mvnp1) : basebuildnumber
adjustedchangecount = incrementrevision(changecount, basebuildnumber)
echo "Adjusted change count: ${adjustedchangecount}"
if (isUnix()) {
gitrevision = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
@ -136,10 +144,9 @@ String generate(meta, String sourcerevision, String sourcepath, int basebuildnum
return buildstamp
}
int incrementrevision(int current, int increment) {
def int newrevision = (current + increment) % (maxversionnumber() + 1)
echo "Current revision: ${current} Increment: ${increment} New revision: ${newrevision}"
return newrevision
String generate(meta, String sourcerevision, String sourcepath, String basebuildnumber) {
def int bbn = basebuildnumber.trim().toInteger()
return generate(meta, sourcerevision, sourcepath, bbn)
}
return this;