如何使用特定参数指定 Task("A").IsDependantOn("B")
How to specify Task("A").IsDependantOn("B") with specific arguments
我正在使用 Cakebuild 定义标准任务依赖项:
var env = Argument("env", "DEV");
//… many tasks
Task("Run-Integration-Tests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
我希望 "Run-Integration-Tests" 依赖于 "Build",特别是 "UAT" 的 "env" 参数(因此如果未通过,则设置为 "UAT" ).可能吗?
您可以为任务添加条件:
var env = Argument("env", "DEV");
Task("Run-Integration-Tests")
.WithCriteria(env == "UAT")
.IsDependentOn("Build")
.Does(() => { ... })
仅当 env
设置为“UAT”时才会 运行 Run-Integration-Tests
任务。
我做了一个有条件地替换变量的方法。
void ArgumentIfTask<T>(string taskName, ref T argument, string argumentName, T argumentValue)
{
if(Argument("target", "Default") != taskName)
{
return;
}
argument = Argument(argumentName, argumentValue);
}
var env = Argument("env", "DEV");
//… many tasks
ArgumentIfTask("Run-Integration-Tests", ref env, "env", "UAT");
Task("Run-Integration-Tests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
可以在执行脚本之前操纵 Cake 使用的有向无环图 (DAG)。这可以通过将任务定义为变量,然后根据需要调用任务的方法来完成。例如:
var IntegrationTask = Task("Run-Integration-Tests")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
然后,在您的脚本中的其他位置执行:
if(env == "UAT")
{
IntegrationTask.IsDependentOn("Build");
}
此技术在 Cake.Recipe 中被广泛使用,以根据正在构建的项目类型来操作 DAG。可以在这里看到一个例子:
https://github.com/cake-contrib/Cake.Recipe/blob/develop/Cake.Recipe/Content/build.cake#L549-L590
即:
private static void SetupTasks(bool isDotNetCoreBuild)
{
var prefix = isDotNetCoreBuild ? "DotNetCore-" : "";
BuildParameters.Tasks.CreateNuGetPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.DupFinderTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.InspectCodeTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.PackageTask.IsDependentOn("Analyze");
BuildParameters.Tasks.PackageTask.IsDependentOn("Test");
BuildParameters.Tasks.PackageTask.IsDependentOn("Create-NuGet-Packages");
BuildParameters.Tasks.PackageTask.IsDependentOn("Create-Chocolatey-Packages");
BuildParameters.Tasks.UploadCodecovReportTask.IsDependentOn("Test");
BuildParameters.Tasks.UploadCoverallsReportTask.IsDependentOn("Test");
BuildParameters.Tasks.AppVeyorTask.IsDependentOn("Upload-Coverage-Report");
BuildParameters.Tasks.AppVeyorTask.IsDependentOn("Publish-Chocolatey-Packages");
BuildParameters.Tasks.InstallReportGeneratorTask.IsDependentOn(prefix + "Build");
if (!isDotNetCoreBuild)
{
if (BuildParameters.TransifexEnabled)
{
BuildParameters.Tasks.BuildTask.IsDependentOn("Transifex-Pull-Translations");
}
BuildParameters.Tasks.TestTask.IsDependentOn("Test-NUnit");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-xUnit");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-MSTest");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-VSTest");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-Fixie");
BuildParameters.Tasks.InstallOpenCoverTask.IsDependentOn("Install-ReportUnit");
}
else
{
if (BuildParameters.TransifexEnabled)
{
BuildParameters.Tasks.DotNetCoreBuildTask.IsDependentOn("Transifex-Pull-Translations");
}
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Test");
BuildParameters.Tasks.InstallOpenCoverTask.IsDependentOn("Install-ReportGenerator");
BuildParameters.Tasks.PackageTask.IsDependentOn(prefix + "Pack");
}
}
我正在使用 Cakebuild 定义标准任务依赖项:
var env = Argument("env", "DEV");
//… many tasks
Task("Run-Integration-Tests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
我希望 "Run-Integration-Tests" 依赖于 "Build",特别是 "UAT" 的 "env" 参数(因此如果未通过,则设置为 "UAT" ).可能吗?
您可以为任务添加条件:
var env = Argument("env", "DEV");
Task("Run-Integration-Tests")
.WithCriteria(env == "UAT")
.IsDependentOn("Build")
.Does(() => { ... })
仅当 env
设置为“UAT”时才会 运行 Run-Integration-Tests
任务。
我做了一个有条件地替换变量的方法。
void ArgumentIfTask<T>(string taskName, ref T argument, string argumentName, T argumentValue)
{
if(Argument("target", "Default") != taskName)
{
return;
}
argument = Argument(argumentName, argumentValue);
}
var env = Argument("env", "DEV");
//… many tasks
ArgumentIfTask("Run-Integration-Tests", ref env, "env", "UAT");
Task("Run-Integration-Tests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
可以在执行脚本之前操纵 Cake 使用的有向无环图 (DAG)。这可以通过将任务定义为变量,然后根据需要调用任务的方法来完成。例如:
var IntegrationTask = Task("Run-Integration-Tests")
.Does(() =>
{
NUnit("./src/**/bin/release/*.Tests.dll");
});
然后,在您的脚本中的其他位置执行:
if(env == "UAT")
{
IntegrationTask.IsDependentOn("Build");
}
此技术在 Cake.Recipe 中被广泛使用,以根据正在构建的项目类型来操作 DAG。可以在这里看到一个例子:
https://github.com/cake-contrib/Cake.Recipe/blob/develop/Cake.Recipe/Content/build.cake#L549-L590
即:
private static void SetupTasks(bool isDotNetCoreBuild)
{
var prefix = isDotNetCoreBuild ? "DotNetCore-" : "";
BuildParameters.Tasks.CreateNuGetPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.DupFinderTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.InspectCodeTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.PackageTask.IsDependentOn("Analyze");
BuildParameters.Tasks.PackageTask.IsDependentOn("Test");
BuildParameters.Tasks.PackageTask.IsDependentOn("Create-NuGet-Packages");
BuildParameters.Tasks.PackageTask.IsDependentOn("Create-Chocolatey-Packages");
BuildParameters.Tasks.UploadCodecovReportTask.IsDependentOn("Test");
BuildParameters.Tasks.UploadCoverallsReportTask.IsDependentOn("Test");
BuildParameters.Tasks.AppVeyorTask.IsDependentOn("Upload-Coverage-Report");
BuildParameters.Tasks.AppVeyorTask.IsDependentOn("Publish-Chocolatey-Packages");
BuildParameters.Tasks.InstallReportGeneratorTask.IsDependentOn(prefix + "Build");
if (!isDotNetCoreBuild)
{
if (BuildParameters.TransifexEnabled)
{
BuildParameters.Tasks.BuildTask.IsDependentOn("Transifex-Pull-Translations");
}
BuildParameters.Tasks.TestTask.IsDependentOn("Test-NUnit");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-xUnit");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-MSTest");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-VSTest");
BuildParameters.Tasks.TestTask.IsDependentOn("Test-Fixie");
BuildParameters.Tasks.InstallOpenCoverTask.IsDependentOn("Install-ReportUnit");
}
else
{
if (BuildParameters.TransifexEnabled)
{
BuildParameters.Tasks.DotNetCoreBuildTask.IsDependentOn("Transifex-Pull-Translations");
}
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Test");
BuildParameters.Tasks.InstallOpenCoverTask.IsDependentOn("Install-ReportGenerator");
BuildParameters.Tasks.PackageTask.IsDependentOn(prefix + "Pack");
}
}