Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain Dotnet goals fail due to injected configfile argument #712

Open
PM-JoakimGustavsson opened this issue Feb 23, 2023 · 0 comments
Open
Labels
bug Create a report to help us improve

Comments

@PM-JoakimGustavsson
Copy link

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:

And gets injected here:

private void prepareAndRunCmd() throws Exception {
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
List<String> extraArgs = new ArrayList<>();
File configFile = prepareConfig(artifactoryManager);
if (configFile != null) {
String configPath = configFile.getAbsolutePath();
extraArgs = StringUtils.isBlank(configPath) ? null : Arrays.asList(toolchainDriver.getFlagSyntax(ToolchainDriverBase.CONFIG_FILE_FLAG), configPath);
}
toolchainDriver.runCmd(nugetCmdArgs, extraArgs, null, true);
}
}

To Reproduce
In order to reproduce it from the Jfrog-CLI tools see jfrog/jfrog-cli#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
  1. 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

  • Extractor version: Seems to affect the most recent version given the source code references provided.
  • Operating system: Seems to affect both Windows and Linux.
  • Artifactory Version: 7.49.3

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.

@PM-JoakimGustavsson PM-JoakimGustavsson added the bug Create a report to help us improve label Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Create a report to help us improve
Projects
None yet
Development

No branches or pull requests

1 participant