- Is it possible to publish an build artifact to Azure Devops/TFS through build.cake script?
- Where should the responsibility for publishing the build artifact be configured when converting to cake scripts, in the build.cake script or in the Azure DevOps pipeline?
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");
});