Publish build artifact through build.cake instead of Azure Devops

Emir Husic
  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");
    });
devlead

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

azure devops: copy and publish build artifacts - rename artifact by buildnumber

Is it possible to conditionally set the artifact name in my Azure DevOps build pipeline "publish artifact" task?

Publish latest build artifact from "LOCAL" Jenkins to Azure DevOps Release Pipeline?

How to refer previous task and stop the build in azure devops if there is no new data to publish an artifact

When using Azure DevOps CI/CD for a Linux web app how can I zip and publish the build artifact as a zip file only instead of copying to directory

where is Azure DevOps build artifact stored

Report .NET Core XUnit tests through Cake build script so that Azure DevOps can use it

Latest build not found while downloading latest version of build artifact in Azure DevOps build definition

Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline?

How to publish build output to network share with Azure Devops

Dotnet publish on linux error in docker (Azure DevOps build)

Azure Devops - Publish Pipelines Artifacts: Build Id is not valid

How to publish docker image as an artifact in azure devops

File pattern for Publish Pipeline Artifact in Azure DevOps

How to copy an Azure DevOps build artifact to a Docker image build in the same pipeline?

Azure Devops Build Policies

Azure DevOps Build Submodule

Azure Devops - Build Automation

Azure DevOps Build with Parameters

Azure DevOps - use GUI instead of YAML to edit build pipeline

Cake build script fails in Azure Devops with mixed .NET core and framework solution

GitVersion task in Cake Build script is missing library on Azure DevOps when run

Can I get NugetRestore to work with build.cake on azure devops (TFS)

Azure DevOps Build - publish doesn't create .compiled files in bin folder on publish

Start a build and passing variables through Azure DevOps Rest API

Azure devops pass build parameters through Rest API

How to publish specific files using Publish Build Artifact Task

How can I inject Azure DevOps pipeline run number in a build artifact file?

Azure Devops pipeline build failure Failed to execute goal The artifact information is incomplete or not valid 'version' is missing