diff --git a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePlugin.groovy b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePlugin.groovy index 40aebc4..58beaa7 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePlugin.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePlugin.groovy @@ -131,6 +131,10 @@ class AzureFileStoragePlugin implements ExecutionFileStoragePlugin, ExecutionMul container.createIfNotExists() } + protected static boolean isImportedExecution(Map context){ + return context != null && context.get("isRemoteFilePath") != null && context.get("isRemoteFilePath") == "true" + } + @Override boolean isAvailable(String filetype) throws ExecutionFileStorageException { try { @@ -225,7 +229,10 @@ class AzureFileStoragePlugin implements ExecutionFileStoragePlugin, ExecutionMul */ static String expandPath(String pathFormat, Map context) { String result = pathFormat.replaceAll("^/+", ""); - if (null != context) { + + if(isImportedExecution(context)) + result = String.valueOf(context.get("outputfilepath").toString()) + else if (null != context) { result = DataContextUtils.replaceDataReferences( result, DataContextUtils.addContext("job", stringMap(context), new HashMap<>()), @@ -252,12 +259,16 @@ class AzureFileStoragePlugin implements ExecutionFileStoragePlugin, ExecutionMul } String getFileName(String fileType){ - String executionId=context.get(META_EXECID) - String project=context.get(META_PROJECT) - - String fileName="${project}/${executionId}.${fileType}" + String fileName + if(isImportedExecution(this.context)) + fileName = expandedPath.substring(expandedPath.indexOf("/"), expandedPath.length()).toLowerCase() + else{ + String executionId=context.get(META_EXECID) + String project=context.get(META_PROJECT) + fileName = "${project}/${executionId}" + } - return fileName + return fileName + ".${fileType}" } diff --git a/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePluginSpec.groovy b/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePluginSpec.groovy index 75bdf86..bea8c1a 100644 --- a/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePluginSpec.groovy +++ b/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureFileStoragePluginSpec.groovy @@ -53,6 +53,21 @@ class AzureFileStoragePluginSpec extends Specification{ thrown IllegalArgumentException } + def "return true if it was initialized with an imported execution"(){ + when: + boolean isImportedExecution = AzureFileStoragePlugin.isImportedExecution(context) + + then: + isImportedExecution == expected + + where: + context | expected + ['isRemoteFilePath': 'asd'] | false + ['isRemoteFilePath': 'true'] | true + [:] | false + null | false + } + private HashMap testContext() { HashMap stringHashMap = new HashMap();