Skip to content

Commit

Permalink
Don't set output variable and Log warning if docker command output le…
Browse files Browse the repository at this point in the history
…ngth more than 32k (#8968)
  • Loading branch information
vithati authored Nov 30, 2018
1 parent ea00a0c commit 593108f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
"loc.messages.NoImagesInImageNamesFile": "At least one image name is expected in file '%s'.",
"loc.messages.CantWriteDataToFile": "Can not write data to the file %s. Error: %s",
"loc.messages.NoDataWrittenOnFile": "No data was written into the file %s",
"loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s."
"loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.",
"loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s"
}
9 changes: 8 additions & 1 deletion Tasks/DockerV0/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tl.cd(tl.getInput("cwd"));
// get the registry server authentication provider
var registryType = tl.getInput("containerregistrytype", true);
var authenticationProvider : AuthenticationTokenProvider;
const environmentVariableMaximumSize = 32766;

if(registryType == "Azure Container Registry"){
authenticationProvider = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry"));
Expand Down Expand Up @@ -84,7 +85,13 @@ require({
connection.close();
})
.then(function success() {
tl.setVariable("DockerOutput", result);
var commandOutputLength = result.length;
if (commandOutputLength > environmentVariableMaximumSize) {
tl.warning(tl.loc('OutputVariableDataSizeExceeded', commandOutputLength, environmentVariableMaximumSize));
} else {
tl.setVariable("DockerOutput", result);
}

tl.setResult(tl.TaskResult.Succeeded, "");
}, function failure(err) {
tl.setResult(tl.TaskResult.Failed, err.message);
Expand Down
5 changes: 3 additions & 2 deletions Tasks/DockerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 0,
"Minor": 3,
"Patch": 23
"Patch": 26
},
"demands": [],
"preview": "false",
Expand Down Expand Up @@ -339,6 +339,7 @@
"NoImagesInImageNamesFile": "At least one image name is expected in file '%s'.",
"CantWriteDataToFile": "Can not write data to the file %s. Error: %s",
"NoDataWrittenOnFile": "No data was written into the file %s",
"FileContentSynced": "Synced the file content to the disk. The content is %s."
"FileContentSynced": "Synced the file content to the disk. The content is %s.",
"OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s"
}
}
5 changes: 3 additions & 2 deletions Tasks/DockerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 0,
"Minor": 3,
"Patch": 22
"Patch": 26
},
"demands": [],
"preview": "false",
Expand Down Expand Up @@ -339,6 +339,7 @@
"NoImagesInImageNamesFile": "ms-resource:loc.messages.NoImagesInImageNamesFile",
"CantWriteDataToFile": "ms-resource:loc.messages.CantWriteDataToFile",
"NoDataWrittenOnFile": "ms-resource:loc.messages.NoDataWrittenOnFile",
"FileContentSynced": "ms-resource:loc.messages.FileContentSynced"
"FileContentSynced": "ms-resource:loc.messages.FileContentSynced",
"OutputVariableDataSizeExceeded": "ms-resource:loc.messages.OutputVariableDataSizeExceeded"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
"loc.messages.CantWriteDataToFile": "Can not write data to the file %s. Error: %s",
"loc.messages.NoDataWrittenOnFile": "No data was written into the file %s",
"loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.",
"loc.messages.DockerRegistryNotFound": "Docker registry service connection not specified."
"loc.messages.DockerRegistryNotFound": "Docker registry service connection not specified.",
"loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s"
}
9 changes: 8 additions & 1 deletion Tasks/DockerV1/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tl.setResourcePath(path.join(__dirname, 'task.json'));
// get the registry server authentication provider
var registryType = tl.getInput("containerregistrytype", true);
var authenticationProvider : AuthenticationTokenProvider;
const environmentVariableMaximumSize = 32766;

if(registryType == "Azure Container Registry"){
authenticationProvider = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry"));
Expand Down Expand Up @@ -68,7 +69,13 @@ commandImplementation.run(connection, (data) => result += data)
}
})
.then(function success() {
tl.setVariable("DockerOutput", result);
var commandOutputLength = result.length;
if (commandOutputLength > environmentVariableMaximumSize) {
tl.warning(tl.loc('OutputVariableDataSizeExceeded', commandOutputLength, environmentVariableMaximumSize));
} else {
tl.setVariable("DockerOutput", result);
}

tl.setResult(tl.TaskResult.Succeeded, "");
}, function failure(err) {
tl.setResult(tl.TaskResult.Failed, err.message);
Expand Down
5 changes: 3 additions & 2 deletions Tasks/DockerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 21
"Patch": 23
},
"demands": [],
"releaseNotes": "Simplified the task by:<br/>&nbsp;- Providing an option to simply select or type a command.<br/>&nbsp;- Retaining the useful input fields and providing an option to pass the rest as an argument to the command.",
Expand Down Expand Up @@ -372,6 +372,7 @@
"CantWriteDataToFile": "Can not write data to the file %s. Error: %s",
"NoDataWrittenOnFile": "No data was written into the file %s",
"FileContentSynced": "Synced the file content to the disk. The content is %s.",
"DockerRegistryNotFound": "Docker registry service connection not specified."
"DockerRegistryNotFound": "Docker registry service connection not specified.",
"OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s"
}
}
5 changes: 3 additions & 2 deletions Tasks/DockerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 21
"Patch": 23
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -372,6 +372,7 @@
"CantWriteDataToFile": "ms-resource:loc.messages.CantWriteDataToFile",
"NoDataWrittenOnFile": "ms-resource:loc.messages.NoDataWrittenOnFile",
"FileContentSynced": "ms-resource:loc.messages.FileContentSynced",
"DockerRegistryNotFound": "ms-resource:loc.messages.DockerRegistryNotFound"
"DockerRegistryNotFound": "ms-resource:loc.messages.DockerRegistryNotFound",
"OutputVariableDataSizeExceeded": "ms-resource:loc.messages.OutputVariableDataSizeExceeded"
}
}

0 comments on commit 593108f

Please sign in to comment.