Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops Pipelines - connect "VS Build" step to "Archive Files" step

I'm trying to get into using Azure Devops Pipelines, and my first pet project is a simple .NET command line app I'm trying to get to be built.

I picked the "VS Build .NET Desktop" task template, and the build per se works fine - the bits are compiled without trouble

YAML:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Log:

##[section]Starting: VSBuild
==============================================================================
Task         : Visual Studio build
Description  : Build with MSBuild and set the Visual Studio version property
Version      : 1.151.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================

##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "d:\a\1\s\AzureDevopsTaskCreator.sln" 
...(lots of lines omitted)
CopyFilesToOutputDirectory:
  Copying file from "d:\a\1\s\obj\Release\AZTaskCreator.exe" to "d:\a\1\s\bin\Release\AZTaskCreator.exe".
  AZTaskCreator -> d:\a\1\s\bin\Release\AZTaskCreator.exe
  Copying file from "d:\a\1\s\obj\Release\AZTaskCreator.pdb" to "d:\a\1\s\bin\Release\AZTaskCreator.pdb".

But now I wanted to somehow publish the output from this build so I could download it (or deploy it somewhere). But I've been struggling with getting these things hooked up.

So I tried to first zip the build output into an archive (which could then be published):

YAML

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.BinariesDirectory)'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/AZCreateTasks$(Build.BuildId).zip'
    replaceExistingArchive: true
    verbose: true

Log:

##[section]Starting: ArchiveFiles  
##[command]d:\a\_tasks\ArchiveFiles_d8b84976-e99a-4b86-b885-4849694435b0\2.151.2\7zip\7z.exe a -tzip -bb3 d:\a\1\a\AZCreateTasks8.zip @d:\a\_temp\yat6561e8redmiomp7bbuik9

My problem is: HOW can I tell the "Archive Files" step to use the output directory of the previous build? I was assuming that the default $(Build.BinariesDirectory) would do that - but obviously, it doesn't:

  • Output from VS Build goes to the d:\a\1\s\bin\Release\ directory
  • Archive files step zips up files in d:\a\_temp\yat6561e8redmiomp7bbuik9 directory

How can I "connect" these two steps so that the "Archive Files" step actually respects and uses the output directory of the VS Build step??

I'm having a terribly hard time finding any useful documentation on what kind of "system pre-defined" magic variables are in play here, and how to influence these .....

like image 616
marc_s Avatar asked Jun 24 '19 07:06

marc_s


People also ask

What is the difference between build and release pipeline in Azure DevOps?

A Build Pipeline is used to generate Artifacts out of Source Code. A Release Pipeline consumes the Artifacts and conducts follow-up actions within a multi-staging system. It is best practice to establish a link between a Build Pipeline and the corresponding Release Pipeline.

What are the two ways for Azure pipelines to be built?

Azure DevOps supports two forms of version control - Git and Azure Repos. Any changes you push to your version control repository will be automatically built and validated.

Should I use Azure pipelines or GitHub actions?

Key differencesGitHub Actions uses YAML files to define workflows and does not support a graphical editor. Azure Pipelines allows you to omit some structure in job definitions. For example, if you only have a single job, you don't need to define the job and only need to define its steps.


1 Answers

According to the log, the build output is in d:\a\1\s\... the s folder it the sources directory, to access this folder there is pre-defined varaible: Build.SourcesDirectory.

So instead of using $(Build.BinariesDirectory) use the above variable:

rootFolderOrFile: '$(Build.SourcesDirectory)'

But now you will get a zip with the sources files including the dll's, so consider to append the path until the folder/s you want.

For example:

rootFolderOrFile: '$(Build.SourcesDirectory)/obj/Release'
like image 84
Shayki Abramczyk Avatar answered Sep 27 '22 22:09

Shayki Abramczyk