Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish build artifact through build.cake instead of Azure Devops

Tags:

  1. Is it possible to publish an build artifact to Azure Devops/TFS through build.cake script?
  2. 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");
    });
like image 625
Emir Husic Avatar asked Jul 31 '19 13:07

Emir Husic


People also ask

How do you publish build Artifacts on Azure DevOps?

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.


1 Answers

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

like image 90
devlead Avatar answered Sep 30 '22 19:09

devlead