From bc67f4dad128a81d3a081b71da6fdb8bec164a78 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Sun, 15 Sep 2019 14:17:49 +0100 Subject: [PATCH] GIS-1621 - Use script prompting to obtain publishing info from user --- publish/ftp_query.groovy | 18 +++++ publish/promptingpublish.groovy | 129 ++++++++++++++++++++++++++++++++ remoteaccess/ftp.groovy | 33 ++++++++ remoteaccess/hostedftp.groovy | 28 +++++++ versioncontrol/git.groovy | 6 ++ 5 files changed, 214 insertions(+) create mode 100644 publish/ftp_query.groovy create mode 100644 publish/promptingpublish.groovy create mode 100644 remoteaccess/ftp.groovy create mode 100644 remoteaccess/hostedftp.groovy diff --git a/publish/ftp_query.groovy b/publish/ftp_query.groovy new file mode 100644 index 0000000..02a4c2d --- /dev/null +++ b/publish/ftp_query.groovy @@ -0,0 +1,18 @@ +ftpremote = load("${autobuilder.commonscripts()}/remoteaccess/ftp.groovy") + +def getCustomerListFromFTP(FTPSiteInfo ftpsiteinfo) { + def List customerfilenames = new ArrayList() + def List customers = new ArrayList() + + FTPClient ftpclient = ftpremote.createFTPClient(ftpsiteinfo) + + customerfilenames = ftpclient.listNames() + for(customer in customerfilenames) { + def String converted = new String(customer.getBytes("ISO-8859-1"), "UTF-8") + customers.add(converted) + } + ftpclient.disconnect() + return customers +} + +return this; diff --git a/publish/promptingpublish.groovy b/publish/promptingpublish.groovy new file mode 100644 index 0000000..deffec8 --- /dev/null +++ b/publish/promptingpublish.groovy @@ -0,0 +1,129 @@ +pipeline { + agent { label "${AGENT_LABEL}" } + stages { + stage('Initial setup') { + steps { + script { + meta = load("${WORKSPACE}/autobuild/Common_scripts/autobuilder.groovy").startnonbuild(this) + } + } + } + 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 = "origin/master" + SOURCEDIR = "${WORKSPACE}/whole" + configurationhelper.gitCheckoutAndRegister(meta, 'whole', SOURCEURL, SOURCEREVISION, SOURCEDIR, '', 0, false) + } + } + } + stage('Identify customer to publish to') { + steps { + script { + hostedftb = load("${autobuilder.commonscripts()}/remoteaccess/hostedftp.groovy") + def List customers = hostedftb.getCustomerList() + customer = input( + message: 'Please select customer to publish to', + ok: 'Ok', + parameters: [ + choice(name: 'customer', choices: customers, description: 'Which customer?') + ] + ) + echo "Chosen customer is: ${customer}" + } + } + } + stage('Identify software release to publish') { + steps { + script { + gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy") + def List releases = gh.gettaglist(SOURCEDIR) + release = input( + message: 'Please select the software version', + ok: 'Ok', + parameters: [ + choice(name: 'release', choices: releases, description: 'Which release?') + ] + ) + echo "Chosen software version is: ${release}" + } + } + } + stage('Checkout release repo at selected software version') { + steps { + script { + SOURCEURL = RELEASE_REPO + SOURCEREVISION = "refs/tags/${release}" + SOURCEDIR = "${WORKSPACE}/whole" + configurationhelper.gitCheckoutAndRegister(meta, 'whole', SOURCEURL, SOURCEREVISION, SOURCEDIR, '', 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") + (summarystring, markunstable, unstablereason) = publisher.publishhierarchy(releasemeta, ITEMS_TO_PUBLISH, customer, 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' + } + } +} + diff --git a/remoteaccess/ftp.groovy b/remoteaccess/ftp.groovy new file mode 100644 index 0000000..750319f --- /dev/null +++ b/remoteaccess/ftp.groovy @@ -0,0 +1,33 @@ +@Grab(group='commons-net', module='commons-net', version='2.0') +import org.apache.commons.net.ftp.FTPClient + +class FTPSiteInfo { + String url + String username + String password + String workingdirectory + + FTPSiteInfo(String url, String username, String password, String workingdirectory) { + this.url = url + this.username = username + this.password = password + this.workingdirectory = workingdirectory + } +} + +FTPSiteInfo createFTPSiteInfo(String url, String username, String password, String workingdirectory) { + FTPSiteInfo ftpsiteinfo = new FTPSiteInfo(url, username, password, workingdirectory) + return ftpsiteinfo +} + +FTPClient createFTPClient(FTPSiteInfo ftpsiteinfo) { + FTPClient ftpclient = new FTPClient().with { + connect ftpsiteinfo.url + enterLocalPassiveMode() + login ftpsiteinfo.username, ftpsiteinfo.password + changeWorkingDirectory ftpsiteinfo.workingdirectory + } + return ftpclient +} + +return this; \ No newline at end of file diff --git a/remoteaccess/hostedftp.groovy b/remoteaccess/hostedftp.groovy new file mode 100644 index 0000000..fd81d6d --- /dev/null +++ b/remoteaccess/hostedftp.groovy @@ -0,0 +1,28 @@ +ftpremote = load("${autobuilder.commonscripts()}/remoteaccess/ftp.groovy") + +FTPSiteInfo getHostedFTPSiteInfo() { + FTPSiteInfo hostedftpsiteinfo = + ftpremote.createFTPSiteInfo("ftp.hostedftp.com", + "ftp@globalinkjetsystems.com", + "ramshorn42", + "/Customers/") + return hostedftpsiteinfo +} + +def getCustomerList() { + def List customerfilenames = new ArrayList() + def List customers = new ArrayList() + + FTPSiteInfo ftpsiteinfo = getHostedFTPSiteInfo() + FTPClient ftpclient = ftpremote.createFTPClient(ftpsiteinfo) + + customerfilenames = ftpclient.listNames() + for(customer in customerfilenames) { + def String converted = new String(customer.getBytes("ISO-8859-1"), "UTF-8") + customers.add(converted) + } + ftpclient.disconnect() + return customers +} + +return this; \ No newline at end of file diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index bb7c0ce..d24f3ff 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -25,6 +25,12 @@ String getGitInfo(String workingSetRootPath) { } } +List gettaglist(String workingSetRootPath) { + dir(workingSetRootPath) { + return clh.getCommandOutput('git tag --sort=-version:refname') + } +} + @NonCPS def ArrayList sparsecheckoutconfig(ArrayList paths) { ArrayList sparsecheckoutpaths = new ArrayList()