To achieve versioning in our build and release pipelines we decided to move our (gitversion, clean, build, tests, ...) tasks to be handled by a cake script stored in each repository instead.
Is there a way to replace the publish build artifact(Azure DevOps) task with a task in the cake.build? I have searched the official documentation of both Azure and cake but can not seem to find a solution. The first task, copying the build artifacts to a staging directory is possible, however, publishing the artifact - is where it gets complicated.
Currently, a snippet of our build.cake.
Task("Copy-Bin")
.WithCriteria(!isLocalBuild)
.Does(() =>
{
Information($"Creating directory {artifactStagingDir}/drop");
CreateDirectory($"{artifactStagingDir}/drop");
Information($"Copying all files from {solutionDir}/{moduleName}.ServiceHost/bin to {artifactStagingDir}/drop/bin");
CopyDirectory($"{solutionDir}/{moduleName}.ServiceHost/bin", $"{artifactStagingDir}/drop/bin");
// Now we should publish the artifact to TFS/Azure Devops
});
Solution
A snippet of an updated build.cake.
Task("Copy-And-Publish-Artifacts")
.WithCriteria(BuildSystem.IsRunningOnAzurePipelinesHosted)
.Does(() =>
{
Information($"Creating directory {artifactStagingDir}/drop");
CreateDirectory($"{artifactStagingDir}/drop");
Information($"Copying all files from {solutionDir}/{moduleName}.ServiceHost/bin to {artifactStagingDir}/drop/bin");
CopyDirectory($"{solutionDir}/{moduleName}.ServiceHost/bin", $"{artifactStagingDir}/drop/bin");
Information($"Uploading files from artifact directory: {artifactStagingDir}/drop to TFS");
TFBuild.Commands.UploadArtifactDirectory($"{artifactStagingDir}/drop");
});
Yes Cake supports uploading artifacts using it's built-in tfbuild build system provider
Task("UploadArtifacts")
.IsDependentOn("ZipArtifacts")
.WithCriteria(BuildSystem.IsRunningOnAzurePipelinesHosted)
.Does(() => {
TFBuild.Commands.UploadArtifact("website", zipFileName, "website");
TFBuild.Commands.UploadArtifact("website", deployCakeFileName, "website");
});
All TFBuild commands documented at cakebuild.net/api/Cake.Common.Build.TFBuild/TFBuildCommands