问题
I have a VSTS extension with two build tasks, one build task should be available for both VSTS and TFS, the other one only for TFS. Is it possible to configure this for each build task via extension manifest?
回答1:
I have used the following workaround to display message and discontinue the build in TFS.
var collectionUrl = process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"];
var regExpression = new RegExp("^((https?)\:\/\/)(([a-z0-9])+\.)*(visualstudio\.com)");
if(regExpression.test(collectionUrl))
{
//VSTS Detected
}
else
{
//Display message task not compatible with TFS
//Fail the build
}
回答2:
Make the extension manifest indicates that the extension is available only for Team Services (targets = Microsoft.Visualstudio.Services.Cloud
).
回答3:
There isn't any way to achieve this via extension manifest file. A good workaround is just as jessehouwing mentioned: Combine the two build tasks into one, provide an option in build setting to let user select or detect the build environment when running the build task. If TFS is selected or detected, run the code in the two build tasks, otherwise just run the code in the first build task.
来源:https://stackoverflow.com/questions/41499650/how-to-limit-build-task-only-to-vsts-not-tfs