Skip to content

Commit 737b343

Browse files
RTECO-2022 - Fixed the bug in jf mvn --scan command
1 parent 4c19791 commit 737b343

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • artifactory/commands/mvn

artifactory/commands/mvn/mvn.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
1717
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
1818
"github.com/jfrog/jfrog-client-go/utils/errorutils"
19+
"github.com/jfrog/jfrog-client-go/utils/io/content"
1920
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
2021
"github.com/jfrog/jfrog-client-go/utils/log"
2122
"github.com/spf13/viper"
@@ -294,6 +295,23 @@ func (mc *MvnCommand) conditionalUpload() error {
294295
if binariesSpecFile == nil {
295296
return nil
296297
}
298+
// The --scan flag only requests an Xray scan for pass/fail gating; it must not, on its own, deploy artifacts.
299+
// Artifacts are uploaded here only when the Maven goal actually requests deployment (i.e. "install"/"deploy").
300+
// For non-deploy goals (e.g. "clean package --scan") the scan still gates the build, but nothing is uploaded.
301+
if !mc.isDeploymentRequested() {
302+
log.Info("Xray scan completed. Skipping upload because the Maven goal does not request deployment. Only 'install' and 'deploy' goals (including deploy:deploy-file) upload artifacts to Artifactory.")
303+
// The scan already ran for pass/fail gating. Since nothing was uploaded, replace the result with an
304+
// empty one so the command summary does not misreport the scanned artifacts as deployed.
305+
if mc.result != nil && mc.result.Reader() != nil {
306+
if e := mc.result.Reader().Close(); e != nil {
307+
return e
308+
}
309+
}
310+
emptyResult := new(commandsutils.Result)
311+
emptyResult.SetReader(content.NewEmptyContentReader("files"))
312+
mc.setResult(emptyResult)
313+
return nil
314+
}
297315
// First upload binaries
298316
if len(binariesSpecFile.Files) > 0 {
299317
uploadCmd := generic.NewUploadCommand()

0 commit comments

Comments
 (0)