Skip to content

Fix false failure status when running Maven without deploy goal#293

Merged
agrasth merged 6 commits intojfrog:mainfrom
agrasth:fix-maven-false-failure-without-deploy
Oct 29, 2025
Merged

Fix false failure status when running Maven without deploy goal#293
agrasth merged 6 commits intojfrog:mainfrom
agrasth:fix-maven-false-failure-without-deploy

Conversation

@agrasth
Copy link
Copy Markdown
Collaborator

@agrasth agrasth commented Oct 28, 2025

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • Appropriate label is added to auto generate release notes.
  • I used gofmt for formatting the code before submitting the pull request.
  • PR description is clear and concise, and it includes the proposed solution/fix.

Description

GitHub Issue: jfrog/jfrog-cli#2602

This fix introduces intelligent goal detection to control when artifacts are deployed to Artifactory, while preserving backward compatibility for existing workflows.

Problem: Previously, when a deployer was configured, ALL Maven commands would deploy artifacts, regardless of the Maven goal used.

Solution: Only install and deploy goals trigger deployment. Other goals (like compile, package, verify) do not deploy, with a clear warning message.

Before Fix:

$ jf mvn package --detailed-summary
# Result: Deploys to Artifactory (unwanted!)

After Fix:

$ jf mvn package --detailed-summary
15:36:35 [Warn] Deployer repository is configured but Maven goal does not trigger deployment. 
                Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.
[main] INFO ... deploy artifacts set to false, artifacts will not be deployed...
[main] INFO ... BUILD SUCCESS
# Result: No deployment, clear warning message 

Goal-Based Deployment Control

// Deployment enabled only for "install" and "deploy" goals
mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer") || !mc.isDeploymentRequested()

// Warn if deployer configured but not deploying
if vConfig.IsSet("deployer") && mc.deploymentDisabled && !mc.IsXrayScan() {
    log.Warn("Deployer repository is configured but Maven goal does not trigger deployment. " +
             "Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.")
}

Helper Function

func (mc *MvnCommand) isDeploymentRequested() bool {
    for _, goal := range mc.goals {
        // Allow deployment for both "install" and "deploy" goals
        if goal == "install" || goal == "deploy" {
            return true
        }
    }
    return false
}

Testing

Test 1: Maven Without Deploy Goal (Bug Scenario - mvn install)

Before Fix:

$ jf mvn install --detailed-summary
# Result: 
# - SUCCESS JSON showing 2 artifacts
# - Artifacts DEPLOYED to Artifactory  (UNWANTED!)
# - Files shown with Artifactory URLs
# - Exit code: 0

After Fix:

$ jf mvn install --detailed-summary
# Result:
# - No JSON summary (deployment disabled)
# - Extractor: "deploy artifacts set to false" 
# - NO deployment to Artifactory (CORRECT!)
# - Exit code: 0 

Test 2: Maven With Deploy Goal (Existing Functionality)

Before and After (No change - works correctly):

$ jf mvn clean deploy --detailed-summary
{
  "status": "success",
  "totals": {
    "success": 2,
    "failure": 0
  },
  "files": [...]
}
# Exit code: 0 

Test 3: FlexPack Mode

Before and After (No change - unaffected):

$ JFROG_RUN_NATIVE=true jf mvn clean package --build-name=test --build-number=1
# Result: No JSON, exit code 0 

Warning Message

When a deployer is configured but a non-deploying goal is used:

[Warn] Deployer repository is configured but Maven goal does not trigger deployment. 
       Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.

When running 'jf mvn clean package --detailed-summary' with a deployer
configured, the CLI incorrectly reported a failure status even though Maven
reported BUILD SUCCESS. This happened because artifacts were counted as
'deployment failures' when no deployment was requested.

This fix checks if the user explicitly requested deployment by looking for
the 'deploy' goal in the Maven command. If no deploy goal is present,
deployment is disabled, preventing false failure reporting.

Fixes: RTECO-453
@agrasth agrasth requested a review from bhanurp October 28, 2025 07:06
@agrasth agrasth added the bug Something isn't working label Oct 28, 2025
@bhanurp
Copy link
Copy Markdown
Collaborator

bhanurp commented Oct 28, 2025

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • Appropriate label is added to auto generate release notes.
  • I used gofmt for formatting the code before submitting the pull request.
  • PR description is clear and concise, and it includes the proposed solution/fix.

Description

GitHub Issue: jfrog/jfrog-cli#2602

When running jf mvn clean package --detailed-summary with a deployer configured in the Maven configuration, the JFrog CLI incorrectly reports a failure status even though Maven reports BUILD SUCCESS.

Before This Fix

$ jf mvn clean package --detailed-summary
[main] INFO ... BUILD SUCCESS
...
{
  "status": "failure",
  "totals": {
    "success": 0,
    "failure": 2
  }
}
# Exit code: 1 

Root Cause

The issue occurred because:

  1. User has a deployer configured in maven.yaml
  2. User runs jf mvn clean package (no deploy goal)
  3. CLI sets deploymentDisabled = false (because deployer is configured)
  4. Artifacts are built (JAR + POM) but not deployed (as expected)
  5. CLI counts these as "deployment failures" instead of recognizing that no deployment was requested
  6. Exit code becomes 1 (failure) despite Maven succeeding

Solution

Added a helper function isDeploymentRequested() that checks if the user explicitly requested deployment by looking for the deploy goal in the Maven command.

The deployment detection logic now considers three conditions:

mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer") || !mc.isDeploymentRequested()

This ensures that when no deploy goal is present, deployment is disabled, preventing false failure reporting.

Changes Made

Modified: artifactory/commands/mvn/mvn.go

  1. Added helper function (lines 132-141):
// isDeploymentRequested checks if the user explicitly requested deployment
// by looking for "deploy" goal in the Maven command goals.
func (mc *MvnCommand) isDeploymentRequested() bool {
	for _, goal := range mc.goals {
		if goal == "deploy" {
			return true
		}
	}
	return false
}
  1. Updated deployment detection logic (line 117):
// Maven's extractor deploys build artifacts. This should be disabled since there is no intent to deploy anything or deploy upon Xray scan results.
// Also disable deployment if the user didn't explicitly request it (no "deploy" goal in the command).
mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer") || !mc.isDeploymentRequested()

If deployer is set and artifacts are getting created either via package | verify | install goals then isn't jfrog-cli automatically trying to deploy artifacts?

If some customers are using this combination of install and deployer or package and deployer and expects the artifacts to be ployed then this will be regression.

// Maven's extractor deploys build artifacts. This should be disabled since there is no intent to deploy anything or deploy upon Xray scan results.
mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer")
// Also disable deployment if the user didn't explicitly request it (no "deploy" goal in the command).
mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer") || !mc.isDeploymentRequested()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this are we trying to deploy to artifactory? even without mentioning deploy? can you test for mvn install and check if that is the case?

Preserves backward compatibility while fixing unwanted deployments:
- 'jf mvn install': Deploys to Artifactory (backward compatible)
- 'jf mvn deploy': Deploys to Artifactory (standard behavior)
- 'jf mvn package/compile/verify': NO deployment + warning message

When deployer is configured but non-deploying goal is used,
shows warning: 'Deployer repository is configured but Maven goal
does not trigger deployment. Only install and deploy goals will
deploy artifacts to Artifactory.'

Fixes: RTECO-453, GitHub #2602
Comment on lines +120 to +126
if vConfig.IsSet("deployer") && !mc.IsXrayScan() {
if !mc.deploymentDisabled {
log.Info("Deployer repository is configured and deployment goal detected - artifacts will be deployed to Artifactory")
} else {
log.Warn("Deployer repository is configured but Maven goal does not trigger deployment. Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.")
}
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhanurp let me know if we need any logs improvement here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScanDeployableArtifacts() returns both fileSpec and pom.xml values as nil and with an error only then can we warn and return cli with exit code 0?

Comment on lines +121 to +125
if !mc.deploymentDisabled {
log.Info("Deployer repository is configured and deployment goal detected - artifacts will be deployed to Artifactory")
} else {
log.Warn("Deployer repository is configured but Maven goal does not trigger deployment. Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.")
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !mc.deploymentDisabled {
log.Info("Deployer repository is configured and deployment goal detected - artifacts will be deployed to Artifactory")
} else {
log.Warn("Deployer repository is configured but Maven goal does not trigger deployment. Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.")
}
if mc.deploymentDisabled {
log.Warn("Deployer repository is configured but Maven goal does not trigger deployment. Only 'install' and 'deploy' goals will deploy artifacts to Artifactory.")
}

@github-actions
Copy link
Copy Markdown
Contributor

👍 Frogbot scanned this pull request and did not find any new security issues.


- Clarifies that install goal still deploys (preserving backward compatibility)
- Documents warning messages for non-deploying goals
- Updates examples and test results
- Emphasizes goal-based deployment control
@agrasth agrasth force-pushed the fix-maven-false-failure-without-deploy branch from 496e665 to 604c65f Compare October 28, 2025 21:25
@agrasth agrasth merged commit 6abad45 into jfrog:main Oct 29, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants