Skip to content

Commit

Permalink
Merge pull request #3786 from Microsoft/users/biprasad/SupportGlobbing1
Browse files Browse the repository at this point in the history
Support file globbing in deploy package path
  • Loading branch information
bishal-pdMSFT authored Mar 15, 2017
2 parents 79a0976 + 2ab0582 commit a9b5417
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"loc.input.label.baseImage": "Base image",
"loc.input.help.baseImage": "Base image to used fo creating VHD.",
"loc.input.label.packagePath": "Package or folder",
"loc.input.help.packagePath": "Specify the path to deployment package.",
"loc.input.help.packagePath": "Specify the path for deployment package relative to $(System.DefaultWorkingDirectory). Supports minimatch pattern.",
"loc.input.label.deployScriptPath": "Deployment script",
"loc.input.help.deployScriptPath": "Specify the path to powershell or shell script which deploys application.",
"loc.input.label.deployScriptArguments": "Deployment script arguments",
Expand Down Expand Up @@ -43,5 +43,7 @@
"loc.messages.CouldNotDeleteTemporaryTemplateDirectory": "Could not delete temporary template directory %s. Please delete manually.",
"loc.messages.TaskParametersConstructorFailed": "Error happened while initializing task: %s.",
"loc.messages.PackerFixFailed": "Packer fix command failed. This could happen if task does not support packer version.",
"loc.messages.PackerValidateFailed": "Packer validate command failed. This could happen if task does not support packer version."
"loc.messages.PackerValidateFailed": "Packer validate command failed. This could happen if task does not support packer version.",
"loc.messages.DeployPackagePathNotFound": "Not found any file matching pattern: %s under rool folder: %s.",
"loc.messages.ResolvedDeployPackgePath": "Resolved deploy package path: %s."
}
12 changes: 12 additions & 0 deletions Tasks/PackerBuild/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ describe('PackerBuild Suite', function() {
done();
});

it('should fail if deploy package path cannot be globbed', (done:MochaDone) => {
process.env["__deploy_package_found__"] = "false";
let tp = path.join(__dirname, 'L0WindowsFail.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();
process.env["__deploy_package_found__"] = null;

assert(tr.failed, 'task should have failed');
assert(tr.stdout.indexOf("##vso[task.complete result=Failed;]loc_mock_TaskParametersConstructorFailed") != -1, "error message should be right");
done();
});

it('should fail if packer fix exits with non zero code', (done:MochaDone) => {
process.env["__packer_fix_fails__"] = "true";
let tp = path.join(__dirname, 'L0WindowsFail.js');
Expand Down
3 changes: 3 additions & 0 deletions Tasks/PackerBuild/Tests/L0Linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ tr.registerMock('./utilities', {
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
findMatch: function(root: string, patterns: string[] | string) {
return ["/packer-user-scripts/dummy.tar.gz"];
},
getCurrentTime: function() {
return 100;
},
Expand Down
3 changes: 3 additions & 0 deletions Tasks/PackerBuild/Tests/L0Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ tr.registerMock('./utilities', {
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
findMatch: function(root: string, patterns: string[] | string) {
return ["C:\\dummy.zip"];
},
getCurrentTime: function() {
return 100;
},
Expand Down
5 changes: 4 additions & 1 deletion Tasks/PackerBuild/Tests/L0Windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tr.setInput('azureResourceGroup', 'testrg');
tr.setInput('storageAccountName', 'teststorage');
tr.setInput('baseImage', 'MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:windows');
tr.setInput('location', 'South India');
tr.setInput('packagePath', 'C:\\dummy.zip');
tr.setInput('packagePath', '**/*.zip');
tr.setInput('deployScriptPath', 'C:\\deploy.ps1');
tr.setInput('deployScriptArguments', "-target \"subdir 1\" -shouldFail false");
tr.setInput('ConnectedServiceName', 'AzureRMSpn');
Expand Down Expand Up @@ -65,6 +65,9 @@ tr.registerMock('./utilities', {
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
findMatch: function(root: string, patterns: string[] | string) {
return ["C:\\dummy.zip"];
},
getCurrentTime: function() {
return 100;
},
Expand Down
7 changes: 7 additions & 0 deletions Tasks/PackerBuild/Tests/L0WindowsFail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ tr.registerMock('./utilities', {
writeFile: function(filePath: string, content: string) {
console.log("writing to file " + filePath + " content: " + content);
},
findMatch: function(root: string, patterns: string[] | string) {
if(process.env["__deploy_package_found__"] === "false") {
return [];
} else {
return ["C:\\dummy.zip"];
}
},
getCurrentTime: function() {
return 100;
},
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PackerBuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "vsts-tasks-packerbuild",
"main":"main.js",
"dependencies": {
"vsts-task-lib" : "^1.1.0"
"vsts-task-lib" : "^2.0.0-preview"
}
}
18 changes: 16 additions & 2 deletions Tasks/PackerBuild/src/taskParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as tl from "vsts-task-lib/task";
import * as constants from "./constants";
import * as utils from "./utilities";

export default class TaskParameters {
public serviceEndpoint: string;
Expand Down Expand Up @@ -34,8 +35,8 @@ export default class TaskParameters {
this._extractImageDetails();

this.deployScriptPath = tl.getInput(constants.DeployScriptPathInputName, true);
this.packagePath = tl.getInput(constants.DeployPackageInputName, true);
this.deployScriptArguments = tl.getInput(constants.DeployScriptArgumentsInputName, false);
this.packagePath = this._getPackagePath();
this.deployScriptArguments = tl.getPathInput(constants.DeployScriptArgumentsInputName, false);

this.imageUri = tl.getInput(constants.OutputVariableImageUri, false);
this.storageAccountLocation = tl.getInput(constants.OutputVariableImageStorageAccountLocation, false);
Expand All @@ -53,4 +54,17 @@ export default class TaskParameters {
this.imageSku = parts[2];
this.osType = parts[3];
}

private _getPackagePath() {
var packagePath = tl.getInput(constants.DeployPackageInputName, true);
var rootFolder = tl.getVariable('System.DefaultWorkingDirectory');

var matchingFiles = utils.findMatch(rootFolder, packagePath);
if(!utils.HasItems(matchingFiles)) {
throw tl.loc("DeployPackagePathNotFound", packagePath, rootFolder);
}

console.log(tl.loc("ResolvedDeployPackgePath", matchingFiles[0]));
return matchingFiles[0];
}
}
4 changes: 4 additions & 0 deletions Tasks/PackerBuild/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function writeFile(filePath: string, content: string): void {
tl.writeFile(filePath, content);
}

export function findMatch(root: string, patterns: string[] | string): string[] {
return tl.findMatch(root, patterns);
}

export function getTempDirectory(): string {
return os.tmpdir();
}
Expand Down
9 changes: 6 additions & 3 deletions Tasks/PackerBuild/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 0,
"Patch": 10
"Patch": 13
},
"demands": [],
"minimumAgentVersion": "2.0.0",
Expand Down Expand Up @@ -85,7 +85,8 @@
"type": "filePath",
"label": "Package or folder",
"required": true,
"helpMarkDown": "Specify the path to deployment package."
"defaultValue": "**//*.zip",
"helpMarkDown": "Specify the path for deployment package relative to $(System.DefaultWorkingDirectory). Supports minimatch pattern."
},
{
"name": "deployScriptPath",
Expand Down Expand Up @@ -173,6 +174,8 @@
"CouldNotDeleteTemporaryTemplateDirectory": "Could not delete temporary template directory %s. Please delete manually.",
"TaskParametersConstructorFailed": "Error happened while initializing task: %s.",
"PackerFixFailed": "Packer fix command failed. This could happen if task does not support packer version.",
"PackerValidateFailed": "Packer validate command failed. This could happen if task does not support packer version."
"PackerValidateFailed": "Packer validate command failed. This could happen if task does not support packer version.",
"DeployPackagePathNotFound": "Not found any file matching pattern: %s under rool folder: %s.",
"ResolvedDeployPackgePath": "Resolved deploy package path: %s."
}
}
7 changes: 5 additions & 2 deletions Tasks/PackerBuild/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 0,
"Patch": 10
"Patch": 13
},
"demands": [],
"minimumAgentVersion": "2.0.0",
Expand Down Expand Up @@ -85,6 +85,7 @@
"type": "filePath",
"label": "ms-resource:loc.input.label.packagePath",
"required": true,
"defaultValue": "**//*.zip",
"helpMarkDown": "ms-resource:loc.input.help.packagePath"
},
{
Expand Down Expand Up @@ -173,6 +174,8 @@
"CouldNotDeleteTemporaryTemplateDirectory": "ms-resource:loc.messages.CouldNotDeleteTemporaryTemplateDirectory",
"TaskParametersConstructorFailed": "ms-resource:loc.messages.TaskParametersConstructorFailed",
"PackerFixFailed": "ms-resource:loc.messages.PackerFixFailed",
"PackerValidateFailed": "ms-resource:loc.messages.PackerValidateFailed"
"PackerValidateFailed": "ms-resource:loc.messages.PackerValidateFailed",
"DeployPackagePathNotFound": "ms-resource:loc.messages.DeployPackagePathNotFound",
"ResolvedDeployPackgePath": "ms-resource:loc.messages.ResolvedDeployPackgePath"
}
}

0 comments on commit a9b5417

Please sign in to comment.