Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 85e3e94

Browse files
committed
Merge pull request #252 from Microsoft/users/mg/filepath
Users/mg/filepath
2 parents 2509f4b + 33cf73b commit 85e3e94

File tree

3 files changed

+54
-36
lines changed

3 files changed

+54
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vsoagent-installer",
33
"description": "Visual Studio Xplat Build Agent Installer",
44
"main": "bin/install.js",
5-
"version": "0.5.8",
5+
"version": "0.5.9",
66
"vsoAgentInfo": {
77
"serviceMilestone": "1.999.0"
88
},

src/agent/plugins/build/prepare.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
3131

3232
var job: agentifm.JobRequestMessage = executionContext.jobInfo.jobMessage;
3333
var variables: {[key: string]: string} = job.environment.variables;
34-
34+
3535
//
3636
// Get the valid scm providers and filter endpoints
3737
//
@@ -42,13 +42,13 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
4242
supported.push(path.basename(provPath, '.js'));
4343
})
4444
executionContext.debug('valid scm providers: ' + supported);
45-
45+
4646
var endpoints: agentifm.ServiceEndpoint[] = job.environment.endpoints;
4747
var srcendpoints = endpoints.filter(function (endpoint: agentifm.ServiceEndpoint) {
4848
if (!endpoint.type) {
4949
return false;
5050
}
51-
51+
5252
executionContext.info('Repository type: ' + endpoint.type);
5353
return (supported.indexOf(endpoint.type.toLowerCase()) >= 0);
5454
});
@@ -57,7 +57,7 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
5757
callback(new Error('Unsupported SCM system. Supported: ' + supported.toString()));
5858
return;
5959
}
60-
60+
6161
// only support 1 SCM system
6262
var endpoint: agentifm.ServiceEndpoint = srcendpoints[0];
6363

@@ -68,32 +68,32 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
6868
var providerType = endpoint.type.toLowerCase();
6969
executionContext.info('using source provider: ' + providerType);
7070

71-
try {
71+
try {
7272
var provPath = path.join(executionContext.scmPath, providerType);
7373
executionContext.info('loading: ' + provPath);
7474
scmm = require(provPath);
7575
}
7676
catch(err) {
7777
callback(new Error('Source Provider failed to load: ' + providerType));
78-
return;
78+
return;
7979
}
80-
80+
8181
if (!scmm.getProvider) {
8282
callback(new Error('SCM Provider does not implement getProvider: ' + providerType));
8383
return;
8484
}
85-
85+
8686
var scmProvider: cm.IScmProvider = scmm.getProvider(executionContext, endpoint);
8787
scmProvider.initialize();
8888
scmProvider.debugOutput = executionContext.debugOutput;
8989
var hashKey: string = scmProvider.hashKey;
90-
90+
9191
//
9292
// Get source mappings and set variables
9393
//
9494
var workingFolder = variables[cm.vars.agentWorkingDirectory];
9595
var repoPath: string;
96-
96+
9797
var sm: smm.SourceMappings = new smm.SourceMappings(workingFolder, executionContext.hostContext);
9898
sm.supportsLegacyPaths = endpoint.type !== 'tfsversioncontrol';
9999
sm.getSourceMapping(hashKey, job, endpoint)
@@ -102,10 +102,10 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
102102

103103
//
104104
// Variables
105-
//
105+
//
106106
// back compat
107-
variables['build.sourceDirectory'] = repoPath;
108-
107+
variables['build.sourceDirectory'] = repoPath;
108+
109109
variables[cm.vars.buildSourcesDirectory] = repoPath;
110110
variables[cm.vars.systemDefaultWorkingDirectory] = repoPath;
111111
variables[cm.vars.buildArtifactStagingDirectory] = path.join(workingFolder, srcMap.build_artifactstagingdirectory);
@@ -114,10 +114,10 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
114114
variables[cm.vars.buildStagingDirectory] = variables[cm.vars.buildArtifactStagingDirectory];
115115

116116
variables[cm.vars.commonTestResultsDirectory] = path.join(workingFolder, srcMap.common_testresultsdirectory);
117-
var bd = variables[cm.vars.agentBuildDirectory] = path.join(workingFolder, srcMap.agent_builddirectory);
117+
var bd = variables[cm.vars.agentBuildDirectory] = variables[cm.vars.buildBinariesDirectory] = path.join(workingFolder, srcMap.agent_builddirectory);
118118
shell.mkdir('-p', bd);
119119
shell.cd(bd);
120-
120+
121121
//
122122
// Do the work, optionally clean and get sources
123123
//
@@ -130,7 +130,7 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
130130
}
131131
else {
132132
executionContext.info('running clean');
133-
return scmProvider.clean();
133+
return scmProvider.clean();
134134
}
135135
}
136136
else {
@@ -158,16 +158,16 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
158158
if (!taskDef) {
159159
throw new Error('Task definition for ' + task.id + ' not found.');
160160
}
161-
161+
162162
// find the filePath inputs
163163
var filePathInputs: { [key: string]: boolean } = {};
164164
taskDef.inputs.forEach((input: agentifm.TaskInputDefinition) => {
165165
if (input.type === 'filePath') {
166166
filePathInputs[input.name] = true;
167-
trace.write('filePath input: ' + input.name);
167+
trace.write('filePath input: ' + input.name);
168168
}
169169
});
170-
170+
171171
// scan dictionary of input/val for pathInputs
172172
for (var key in task.inputs) {
173173
if (filePathInputs.hasOwnProperty(key)) {
@@ -177,7 +177,7 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
177177
trace.write('rewriting ' + key + ' to ' + resolvedPath);
178178
task.inputs[key] = resolvedPath;
179179
}
180-
}
180+
}
181181
});
182182

183183
return 0;
@@ -186,7 +186,7 @@ export function beforeJob(executionContext: cm.IExecutionContext, callback) {
186186
executionContext.info('CD: ' + repoPath);
187187
shell.cd(repoPath);
188188
callback();
189-
})
189+
})
190190
.fail((err) => {
191191
callback(err);
192192
return;

src/agent/scm/lib/scmprovider.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ScmProvider implements cm.IScmProvider {
1111
this.ctx = ctx;
1212
this.endpoint = endpoint;
1313
this.job = ctx.jobInfo.jobMessage;
14-
this.variables = this.job.environment.variables
14+
this.variables = this.job.environment.variables
1515
}
1616

1717
public ctx: cm.IExecutionContext;
@@ -20,7 +20,7 @@ export class ScmProvider implements cm.IScmProvider {
2020
public job: agentifm.JobRequestMessage;
2121
public variables: {[key: string]: string};
2222
public hashKey: string;
23-
23+
2424
// full path of final root of enlistment
2525
public targetPath: string;
2626

@@ -32,49 +32,67 @@ export class ScmProvider implements cm.IScmProvider {
3232
public setAuthorization(authorization: agentifm.EndpointAuthorization) {
3333

3434
}
35-
35+
3636
// override if it's more complex than just hashing the url
3737
public getHashKey() {
3838
var hash = null;
39-
39+
4040
if (this.endpoint.url) {
4141
var hashProvider = crypto.createHash("sha256");
4242
hashProvider.update(this.endpoint.url, 'utf8');
43-
hash = hashProvider.digest('hex');
43+
hash = hashProvider.digest('hex');
4444
}
45-
45+
4646
return hash;
4747
}
4848

4949
public initialize() {
5050
if (!this.ctx) {
5151
throw (new Error('executionContext null initializing git scm provider'));
5252
}
53-
53+
5454
if (!this.endpoint) {
5555
throw (new Error('endpoint null initializing git scm provider'));
5656
}
5757

5858
this.setAuthorization(this.endpoint.authorization);
59-
59+
6060
this.hashKey = this.getHashKey();
6161
}
6262

6363
public getAuthParameter(authorization: agentifm.EndpointAuthorization, paramName: string) {
6464
var paramValue = null;
6565

6666
if (authorization && authorization['parameters']) {
67-
paramValue = authorization['parameters'][paramName];
67+
paramValue = authorization['parameters'][paramName];
6868
}
69-
69+
7070
return paramValue;
7171
}
72-
72+
73+
private repoRootInFilePath(filePathInput : string) : boolean {
74+
filePathInput = filePathInput.toLowerCase();
75+
if(filePathInput.startsWith('$(' + cm.vars.buildSourcesDirectory.toLowerCase()) ||
76+
filePathInput.startsWith('$(' + cm.vars.buildArtifactStagingDirectory.toLowerCase()) ||
77+
filePathInput.startsWith('$(' + cm.vars.buildStagingDirectory.toLowerCase()) ||
78+
filePathInput.startsWith('$(' + cm.vars.buildBinariesDirectory.toLowerCase()) ||
79+
filePathInput.startsWith('$(' + cm.vars.systemDefaultWorkingDirectory.toLowerCase()) ||
80+
filePathInput.startsWith('$(' + cm.vars.commonTestResultsDirectory.toLowerCase()) ||
81+
filePathInput.startsWith('$(' + cm.vars.agentBuildDirectory.toLowerCase()) ) {
82+
return true;
83+
}
84+
return false;
85+
}
86+
7387
// override if more complex than appending to root of repo
7488
public resolveInputPath(inputPath: string) {
75-
return path.resolve(this.targetPath, inputPath);
89+
if (!this.repoRootInFilePath(inputPath)) {
90+
return path.resolve(this.targetPath, inputPath);
91+
} else {
92+
return inputPath;
93+
}
7694
}
77-
95+
7896
// virtual - must override
7997
public getCode(): Q.Promise<number> {
8098
var defer = Q.defer<number>();
@@ -87,5 +105,5 @@ export class ScmProvider implements cm.IScmProvider {
87105
var defer = Q.defer<number>();
88106
defer.reject(new Error('Must override the clean method'));
89107
return defer.promise;
90-
}
108+
}
91109
}

0 commit comments

Comments
 (0)