diff --git a/vars/deployer.groovy b/vars/deployer.groovy index 9e6e915..85d39ce 100644 --- a/vars/deployer.groovy +++ b/vars/deployer.groovy @@ -1,40 +1,59 @@ def capellaNightlyProduct(String inputPath, String outputDirName) { - def outputPath = getFullCapellaProductPath(outputDirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} mkdir -p ${outputPath}" - sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" - } + if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") + } + else { + def outputPath = getFullCapellaProductPath(outputDirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} mkdir -p ${outputPath}" + sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" + } + } } def capellaNightlyUpdateSite(String inputPath, String outputDirName) { - def outputPath = getFullCapellaUpdateSitePath(outputDirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} mkdir -p ${outputPath}" - sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" - } + if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") + } + else { + def outputPath = getFullCapellaUpdateSitePath(outputDirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} mkdir -p ${outputPath}" + sh "scp -rp ${inputPath} ${sshAccount}:${outputPath}" + } + } } def cleanCapellaNightlyArtefacts(String dirName) { - def productPath = getFullCapellaProductPath(dirName) - def updateSitePath = getFullCapellaUpdateSitePath(dirName) - def sshAccount = getSSHAccount() - - sshagent (['projects-storage.eclipse.org-bot-ssh']) { - sh "ssh ${sshAccount} rm -rf ${productPath}" - sh "ssh ${sshAccount} rm -rf ${updateSitePath}" - } + if (isInvalid(dirName)) { + log.error("Deployment Error: ${dirName} is not recognised") + } + else { + + def productPath = getFullCapellaProductPath(dirName) + def updateSitePath = getFullCapellaUpdateSitePath(dirName) + def sshAccount = getSSHAccount() + + sshagent (['projects-storage.eclipse.org-bot-ssh']) { + sh "ssh ${sshAccount} rm -rf ${productPath}" + sh "ssh ${sshAccount} rm -rf ${updateSitePath}" + } + } } def addonNightlyDropins(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def outputPath = getFullAddonDropinsPath(addonDirName, outputDirName) @@ -48,10 +67,13 @@ def addonNightlyDropins(String inputPath, String outputDirName) { } def addonNightlyUpdateSite(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def outputPath = getFullAddonDropinsUpdateSitePath(addonDirName, outputDirName) @@ -65,11 +87,15 @@ def addonNightlyUpdateSite(String inputPath, String outputDirName) { } def addonNightlyProduct(String inputPath, String outputDirName) { - def addonDirName = getAddonDirName() + def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } + else { def outputPath = getFullAddonProductPath(addonDirName, outputDirName) def sshAccount = getSSHAccount() @@ -84,8 +110,11 @@ def addonNightlyProduct(String inputPath, String outputDirName) { def cleanAddonNightlyArtefacts(String outputDirName) { def addonDirName = getAddonDirName() - if(addonDirName.isEmpty()) { + if(isInvalid(addonDirName)) { log.error("Deployment Error: ${GIT_URL} repository is not recognised") + + } else if (isInvalid(outputDirName)) { + log.error("Deployment Error: ${outputDirName} is not recognised") } else { def dropinPath = getFullAddonDropinsPath(addonDirName, outputDirName) @@ -135,6 +164,10 @@ private def getAddonDirName() { } } +private def isInvalid(path) { + return path.isEmpty() || path.contains('..') +} + private def getSSHAccount() { return "genie.capella@projects-storage.eclipse.org" }