jfrog / build-info

Artifactory's open integration layer for CI build servers
https://www.buildinfo.org
Apache License 2.0
147 stars 155 forks source link

Certain Dotnet goals fail due to injected configfile argument #712

Open PM-JoakimGustavsson opened 1 year ago

PM-JoakimGustavsson commented 1 year ago

Describe the bug When executing a Dotnet build goal the build-info layer seems to inject an additional commandline argument to the dotnet command, namely --configfile. This gets injected at the end of the commandline arguments, after all of the user-provided arguments. This parameter is valid for certain dotnet sub-commands, such as dotnet restore and dotnet build but is not valid for goals such as dotnet test. As a result the underlying MSBuild command will complain about an invalid parameter.

The relevant lines of code are likely the ones below.

The argument is declared here:

https://github.com/jfrog/build-info/blob/67cefb286471634b88e104efe2543ad088010471/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/drivers/ToolchainDriverBase.java#L22

And gets injected here:

https://github.com/jfrog/build-info/blob/642ee6a81fbce07cdc1ca954ca7686ff6495bd48/build-info-extractor-nuget/src/main/java/org/jfrog/build/extractor/nuget/extractor/NugetRun.java#L190-L200

To Reproduce In order to reproduce it from the Jfrog-CLI tools see https://github.com/jfrog/jfrog-cli/issues/1799 In order to reproduce it from the Jenkins Artifactory plugin perform the following steps:

  1. Set up a Jenkins job to build any Dotnet project. The job should use the scripted pipeline syntax as described here: https://www.jfrog.com/confluence/display/JFROG/Scripted+Pipeline+Syntax#ScriptedPipelineSyntax-NuGetand.NETCoreBuildswithArtifactory
  2. Set up the basic Artifactory build integration by adding the following to the scripted pipeline:
    def rtBuild = Artifactory.newDotnetBuild()
    rtBuild.resolver repo: 'nuget-remote', server: server //Replace with a correct Artifactory config
    def buildInfo = rtBuild.run args: 'restore' //This will work as --configfile is valid for restore
    rtBuild.run buildInfo: buildInfo, args: 'build' //This will work as --configfile is valid for build
    rtBuild.run buildInfo: buildInfo, args: 'test' //This will fail as --configfile is not valid for test
  3. Run the Jenkins job. The pipeline will fail with an error message similar to
[skapa-build-integration-for-.net] $ cmd.exe /C "java.exe -Djava.io.tmpdir=D:\JenkinsWorkspace\workspace\skapa-build-integration-for-.net@tmp\artifactory\javatmpdir -cp "D:/JenkinsWorkspace/workspace/skapa-build-integration-for-.net@tmp/artifactory/cache/artifactory-plugin/3.18.0/*" org.jfrog.build.extractor.nuget.extractor.NugetRun && exit %%ERRORLEVEL%%"
feb. 23, 2023 3:28:41 EM org.jfrog.build.extractor.packageManager.PackageManagerLogger info
INFO: Executing command: cmd /c dotnet test  --configfile D:\JenkinsWorkspace\workspace\skapa-build-integration-for-.net@tmp\artifactory\javatmpdir\artifactory.plugin.nuget.config17617277027769088694.tmp
Executing command: cmd /c git log --pretty=format:%s -1
feb. 23, 2023 3:28:41 EM org.jfrog.build.extractor.packageManager.PackageManagerLogger error
SEVERE: MSBUILD : error MSB1001: Unknown switch.
    Full command line: 'C:\Program Files\dotnet\sdk\6.0.405\MSBuild.dll -maxcpucount -verbosity:m -target:VSTest -nodereuse:false -nologo -property:VSTestNoBuild=true  --configfile D:\JenkinsWorkspace\workspace\skapa-build-integration-for-.net@tmp\artifactory\javatmpdir\artifactory.plugin.nuget.config17617277027769088694.tmp -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\6.0.405\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\6.0.405\dotnet.dll'
  Switches appended by response files:
Switch: --configfile

For switch syntax, type "MSBuild -help"

java.io.IOException: MSBUILD : error MSB1001: Unknown switch.

Expected behavior The --configfile parameter should only be injected for dotnet goals that support it. Alternatively the run-command API should provide a parameter to turn off automatic argument injection for that particular goal, e.g

rtBuild.run buildInfo: buildInfo, args: 'test', argumentInjection: false

Obviously the second solution would also require modifications to higher level tools such as the Jenkins plugin and Jfrog CLI and might because of this not be the ideal solution.

Versions

Additional context A workaround is to pass a shell comment symbol at the end of the provided command. Example:

rtBuild.run buildInfo: buildInfo, args: 'test &REM' //For Windows
rtBuild.run buildInfo: buildInfo, args: 'test #' //For Linux

This comments out the injected argument when passed to the shell.