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");
});
See Artifacts in Azure Pipelines. Specify the name of the artifact that you want to create. It can be whatever you want. Choose whether to store the artifact in Azure Pipelines ( Container ), or to copy it to a file share ( FilePath ) that must be accessible from the build agent.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With