'NUKE Build in Azure DevOps Build Pipeline Failing
So I have implemented the NUKE build system in my solution, and everything 100% works locally.
Out in Azure DevOps it's a different story, my YAML task looks like this:
- task: CmdLine@2
displayName: 'NUKE Build'
inputs:
script:
.\src\build package --cfg $(buildConfiguration) --pak $(Build.ArtifactStagingDirectory)
And NUKE does run, but it fails with an error stating it couldn't locate my solution file:
Expected file to exist: D:\a\1\s\**\*.sln
Here is the entire command line log output:
2022-04-08T18:39:07.9969860Z ##[section]Starting: NUKE Build
2022-04-08T18:39:08.0228304Z ==============================================================================
2022-04-08T18:39:08.0228652Z Task : Command line
2022-04-08T18:39:08.0228978Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:39:08.0229274Z Version : 2.201.1
2022-04-08T18:39:08.0229490Z Author : Microsoft Corporation
2022-04-08T18:39:08.0230495Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:39:08.0230888Z ==============================================================================
2022-04-08T18:39:09.5867757Z Generating script.
2022-04-08T18:39:09.6086899Z Script contents: shell
2022-04-08T18:39:09.6117246Z .\src\build package --cfg Release --pak D:\a\1\a
2022-04-08T18:39:09.6712303Z ========================== Starting Command Output ===========================
2022-04-08T18:39:09.7222712Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\ec061a9c-d293-42ca-8b24-3d57ab43d6b1.cmd""
2022-04-08T18:39:10.1964079Z PowerShell Desktop version 5.1.20348.558
2022-04-08T18:39:11.9025685Z Microsoft (R) .NET Core SDK version 6.0.201
2022-04-08T18:39:12.1269858Z
2022-04-08T18:39:12.1299946Z Welcome to .NET 6.0!
2022-04-08T18:39:12.1300642Z ---------------------
2022-04-08T18:39:12.1301057Z SDK Version: 6.0.201
2022-04-08T18:39:12.1301258Z
2022-04-08T18:39:12.1301590Z ----------------
2022-04-08T18:39:12.1302080Z Installed an ASP.NET Core HTTPS development certificate.
2022-04-08T18:39:12.1303932Z To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
2022-04-08T18:39:12.1304429Z Learn about HTTPS: https://aka.ms/dotnet-https
2022-04-08T18:39:12.1305954Z ----------------
2022-04-08T18:39:12.1306300Z Write your first app: https://aka.ms/dotnet-hello-world
2022-04-08T18:39:12.1306678Z Find out what's new: https://aka.ms/dotnet-whats-new
2022-04-08T18:39:12.1307948Z Explore documentation: https://aka.ms/dotnet-docs
2022-04-08T18:39:12.1308586Z Report issues and find source on GitHub: https://github.com/dotnet/core
2022-04-08T18:39:12.1309267Z Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
2022-04-08T18:39:12.1311891Z --------------------------------------------------------------------------------------
2022-04-08T18:39:27.0014563Z ##[warning]Exception has been thrown by the target of an invocation.
2022-04-08T18:39:27.1770000Z [90m18:39:26[0m[90m [[0m[33;1mWRN[0m[90m] [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1771426Z System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1773524Z ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1774228Z ---> System.ArgumentException: Expected file to exist: D:\a\1\s\**\*.sln (Parameter 'path')[0m
2022-04-08T18:39:27.1774784Z [90m at Nuke.Common.Assert.FileExists(String path, String message, String argumentExpression)[0m
2022-04-08T18:39:27.1775284Z [90m at Nuke.Common.IO.TextTasks.ReadAllLines(String path, Encoding encoding)[0m
2022-04-08T18:39:27.1775809Z [90m at Nuke.Common.ProjectModel.SolutionSerializer.DeserializeFromFile[T](String solutionFile)[0m
2022-04-08T18:39:27.1776522Z [90m --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1777060Z [90m at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1778369Z [90m at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)[0m
2022-04-08T18:39:27.1779002Z [90m at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)[0m
2022-04-08T18:39:27.1779785Z [90m at Nuke.Common.ProjectModel.SolutionAttribute.GetValue(MemberInfo member, Object instance)[0m
2022-04-08T18:39:27.1782574Z [90m at Nuke.Common.ValueInjection.ValueInjectionAttributeBase.<>c__DisplayClass0_0.<TryGetValue>b__0()[0m
2022-04-08T18:39:27.1783085Z [90m --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1783634Z [90m at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1784428Z [90m at System.Delegate.DynamicInvokeImpl(Object[] args)[0m
2022-04-08T18:39:27.1784965Z [90m at System.Delegate.DynamicInvoke(Object[] args)[0m
2022-04-08T18:39:27.1786056Z [90m at Nuke.Common.ControlFlow.SuppressErrorsIf(Boolean condition, Delegate action, Object defaultValue, Boolean includeStackTrace, Boolean logWarning)[0m
2022-04-08T18:39:27.2272867Z ?
2022-04-08T18:39:27.2274719Z [97;1m¦¦¦+ ¦¦+¦¦+ ¦¦+¦¦+ ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2275048Z [97;1m¦¦¦¦+ ¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦++¦¦+----+[0m
2022-04-08T18:39:27.2275514Z [97;1m¦¦+¦¦+ ¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦++ ¦¦¦¦¦+ [0m
2022-04-08T18:39:27.2275785Z [97;1m¦¦¦+¦¦+¦¦¦¦¦¦ ¦¦¦¦¦+-¦¦+ ¦¦+--+ [0m
2022-04-08T18:39:27.2276070Z [97;1m¦¦¦ +¦¦¦¦¦+¦¦¦¦¦¦++¦¦¦ ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2276350Z [97;1m+-+ +---+ +-----+ +-+ +-++------+[0m
2022-04-08T18:39:27.2276564Z ?
2022-04-08T18:39:27.2437288Z [36;1mNUKE Execution Engine version 6.0.1 (Windows,.NETCoreApp,Version=v5.0)[0m
2022-04-08T18:39:27.2438057Z ?
2022-04-08T18:39:27.7707082Z ##[warning]Could not complete checking build configurations within 500 milliseconds
2022-04-08T18:39:27.7732088Z [90m18:39:27[0m[90m [[0m[33;1mWRN[0m[90m] [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8279552Z ##[group]Restore
2022-04-08T18:39:31.8446550Z ##[error]Target "Restore" failed
2022-04-08T18:39:31.8794936Z [90m18:39:31[0m[90m [[0m[31;1mERR[0m[90m] [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8796042Z System.NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.8796591Z [90m at Nuke.Common.ProjectModel.Solution.op_Implicit(Solution solution)[0m
2022-04-08T18:39:31.8797101Z [90m at Build.<get_Restore>b__20_2(MSBuildSettings s) in D:\a\1\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8797732Z [90m at Nuke.Common.Tools.MSBuild.MSBuildTasks.MSBuild(Configure`1 configurator)[0m
2022-04-08T18:39:31.8798459Z [90m at Build.<get_Restore>b__20_1() in D:\a\1\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8798994Z [90m at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)[0m
2022-04-08T18:39:31.8799610Z [90m at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)[0m
2022-04-08T18:39:31.8800407Z [90m at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)[0m
2022-04-08T18:39:31.8817982Z ##[endgroup]Restore
2022-04-08T18:39:31.8863504Z ##[group]Warnings & Errors
2022-04-08T18:39:31.8882060Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:31.8884458Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8888070Z [90m[[0m[31;1mERR[0m[90m] [0m[90mRestore[0m[90m: [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8889294Z ##[endgroup]Warnings & Errors
2022-04-08T18:39:31.8932545Z ?
2022-04-08T18:39:31.8933184Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.8933694Z [36;1mTarget Status Duration[0m
2022-04-08T18:39:31.8935167Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9029244Z [31;1mRestore Failed < 1sec // NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.9032700Z [33;1mPreBuild NotRun [0m
2022-04-08T18:39:31.9033326Z [33;1mBuildFrontend NotRun [0m
2022-04-08T18:39:31.9034546Z [33;1mCompile NotRun [0m
2022-04-08T18:39:31.9035764Z [33;1mPublish NotRun [0m
2022-04-08T18:39:31.9036389Z [33;1mPackage NotRun [0m
2022-04-08T18:39:31.9036847Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9037329Z [36;1mTotal < 1sec[0m
2022-04-08T18:39:31.9037792Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9038298Z ?
2022-04-08T18:39:31.9054882Z [31;1mBuild failed on 4/8/2022 6:39:31 PM. (?°?°)?? ???[0m
2022-04-08T18:39:32.1509226Z ##[error]Cmd.exe exited with code '-1'.
2022-04-08T18:39:32.2145341Z ##[section]Finishing: NUKE Build
but I definitely have a solution file at:
D:\a\1\s\src\MySolution.sln
I added a YAML task to 100% confirm it is there (and it's there):
- task: CmdLine@2
displayName: 'List Source Folder'
inputs:
script: 'tree $(Build.SourcesDirectory) /f'
Here is the listing:
2022-04-08T18:57:59.6501952Z ##[section]Starting: List Source Folder
2022-04-08T18:57:59.6793825Z ==============================================================================
2022-04-08T18:57:59.6794430Z Task : Command line
2022-04-08T18:57:59.6794753Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:57:59.6795061Z Version : 2.201.1
2022-04-08T18:57:59.6795267Z Author : Microsoft Corporation
2022-04-08T18:57:59.6795600Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:57:59.6795961Z ==============================================================================
2022-04-08T18:58:02.0506033Z Generating script.
2022-04-08T18:58:02.0739760Z Script contents: shell
2022-04-08T18:58:02.0756595Z tree D:\a\1\s /f
2022-04-08T18:58:02.1475179Z ========================== Starting Command Output ===========================
2022-04-08T18:58:02.1898242Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\5da783bd-9a97-4da8-8bef-3d739b2a3128.cmd""
2022-04-08T18:58:02.2402115Z Folder PATH listing for volume Temp
2022-04-08T18:58:02.2403508Z Volume serial number is 00000247 52D3:EF1F
2022-04-08T18:58:02.2404144Z D:\A\1\S
2022-04-08T18:58:02.2405018Z | .gitignore
2022-04-08T18:58:02.2405560Z | azure-pipelines.yml
2022-04-08T18:58:02.2406147Z | clean.bat
2022-04-08T18:58:02.2406717Z | nuget.config
2022-04-08T18:58:02.2407288Z | README.md
2022-04-08T18:58:02.2407842Z |
2022-04-08T18:58:02.2408341Z +---.nuke
2022-04-08T18:58:02.2409000Z | build.schema.json
2022-04-08T18:58:02.2409391Z | parameters.json
2022-04-08T18:58:02.2409867Z |
2022-04-08T18:58:02.2410372Z +---build
2022-04-08T18:58:02.2410926Z | .editorconfig
2022-04-08T18:58:02.2411502Z | Build.cs
2022-04-08T18:58:02.2412097Z | Configuration.cs
2022-04-08T18:58:02.2412876Z | Directory.Build.props
2022-04-08T18:58:02.2413461Z | Directory.Build.targets
2022-04-08T18:58:02.2414211Z | _build.csproj
2022-04-08T18:58:02.2414923Z | _build.csproj.DotSettings
2022-04-08T18:58:02.2415470Z |
2022-04-08T18:58:02.2535989Z +---src
2022-04-08T18:58:02.2536325Z | build.cmd
2022-04-08T18:58:02.2536699Z | build.ps1
2022-04-08T18:58:02.2536957Z | build.sh
2022-04-08T18:58:02.2537193Z | MySolution.sln
2022-04-08T18:58:02.2537398Z |
.
.
.
Lot's of project folders/files here (removed for brevity)
.
.
.
2022-04-08T18:58:02.3340758Z
2022-04-08T18:58:02.3743539Z ##[section]Finishing: List Source Folder
I'm at a loss (why doesn't it find it?), anyone have any insight on why this might be happening?
Solution 1:[1]
Turns out... what I thought, was NUKE searching for a solution file, was actually not the case at all.
The error:
Expected file to exist: D:\a\1\s\**\*.sln
was due to the existence of a variable that is normally added to the standard YAML pipeline file (for use with NuGet/MSBuild tasks), i.e.
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
- task: NuGetCommand@2
displayName: 'Restore'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: './nuget.config'
- task: VSBuild@1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
That solution: '**/*.sln' was somehow overriding the solution value configured in the parameters.json file. Not 100% sure why... but once that environment variable was removed NUKE began to work as expected.
Solution 2:[2]
.nuke
marks the root directory, so your solution file is located under ./src/MySolution.sln
from there and should also be noted like that in the parameters.json
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Xorcist |
Solution 2 | Matthias |