@@ -707,11 +707,14 @@ func TestGradleBuildPublishWithCIVcsProps(t *testing.T) {
707707 artifactCount := 0
708708 for _ , module := range publishedBuildInfo .BuildInfo .Modules {
709709 for _ , artifact := range module .Artifacts {
710- fullPath := artifact . OriginalDeploymentRepo + "/" + artifact . Path
710+ fullPath := tests . ArtifactFullPath ( artifact , tests . GradleRepo )
711711
712712 props , err := serviceManager .GetItemProps (fullPath )
713713 assert .NoError (t , err , "Failed to get properties for artifact: %s" , fullPath )
714714 assert .NotNil (t , props , "Properties are nil for artifact: %s" , fullPath )
715+ if props == nil {
716+ continue
717+ }
715718
716719 // Validate VCS properties
717720 assert .Contains (t , props .Properties , "vcs.provider" , "Missing vcs.provider on %s" , artifact .Name )
@@ -730,3 +733,104 @@ func TestGradleBuildPublishWithCIVcsProps(t *testing.T) {
730733
731734 cleanGradleTest (t )
732735}
736+
737+ // TestGradleBuildPublishWithLocalGitVcsProps tests that local git VCS properties are set on Gradle artifacts
738+ // when running build-publish with VCS collection enabled and no CI env.
739+ // Uses the traditional Gradle extractor path (not FlexPack) because SetCIVcsPropsToConfig
740+ // injects local git props into the extractor config; FlexPack only sets build.* props on publish.
741+ func TestGradleBuildPublishWithLocalGitVcsProps (t * testing.T ) {
742+ initGradleTest (t )
743+ buildName := "gradle-local-git-test"
744+ buildNumber := "1"
745+
746+ cleanupEnv := tests .SetupLocalGitVcsEnv (t )
747+ defer cleanupEnv ()
748+
749+ _ = os .Unsetenv ("JFROG_RUN_NATIVE" )
750+
751+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
752+ defer inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
753+
754+ buildGradlePath := createGradleProject (t , "gradleproject" )
755+ projectDir := filepath .Dir (buildGradlePath )
756+ tests .CopyGitFixtureIntoProject (t , projectDir )
757+ require .FileExists (t , filepath .Join (projectDir , ".git" , "HEAD" ))
758+
759+ configFilePath := filepath .Join (filepath .FromSlash (tests .GetTestResourcesPath ()), "buildspecs" , tests .GradleConfig )
760+ createConfigFile (filepath .Join (projectDir , ".jfrog" , "projects" ), configFilePath , t )
761+
762+ oldHomeDir := changeWD (t , projectDir )
763+ defer clientTestUtils .ChangeDirAndAssert (t , oldHomeDir )
764+
765+ buildGradlePath = strings .ReplaceAll (buildGradlePath , `\` , "/" )
766+ runJfrogCli (t , "gradle" , "clean" , "artifactoryPublish" , "-b" + buildGradlePath , "--build-name=" + buildName , "--build-number=" + buildNumber )
767+
768+ assert .NoError (t , artifactoryCli .Exec ("bp" , buildName , buildNumber ))
769+
770+ clientTestUtils .ChangeDirAndAssert (t , oldHomeDir )
771+
772+ var publishedBuildInfo * buildinfo.PublishedBuildInfo
773+ var found bool
774+ assert .Eventuallyf (t , func () bool {
775+ var biErr error
776+ publishedBuildInfo , found , biErr = tests .GetBuildInfo (serverDetails , buildName , buildNumber )
777+ return biErr == nil && found
778+ }, 30 * time .Second , 2 * time .Second , "Build info was not found for %s/%s" , buildName , buildNumber )
779+ if ! found || publishedBuildInfo == nil {
780+ return
781+ }
782+
783+ serviceManager , err := utils .CreateServiceManager (serverDetails , 3 , 1000 , false )
784+ assert .NoError (t , err )
785+
786+ artifactCount := tests .ValidateLocalGitVcsPropsOnBuildInfoArtifacts (t , serviceManager , publishedBuildInfo ,
787+ tests .GradleRepo , tests .VcsFixtureMainURL , tests .VcsFixtureMainRevision , tests .VcsFixtureMainBranch )
788+ assert .Greater (t , artifactCount , 0 )
789+
790+ cleanGradleTest (t )
791+ }
792+
793+ // TestGradleFlexPackPublishWithLocalGitVcsProps verifies local git VCS on FlexPack publish path.
794+ func TestGradleFlexPackPublishWithLocalGitVcsProps (t * testing.T ) {
795+ initGradleTest (t )
796+ buildName := "gradle-flexpack-local-git"
797+ buildNumber := "1"
798+
799+ cleanupEnv := tests .SetupLocalGitVcsEnv (t )
800+ defer cleanupEnv ()
801+
802+ setEnvCallBack := clientTestUtils .SetEnvWithCallbackAndAssert (t , "JFROG_RUN_NATIVE" , "true" )
803+ defer setEnvCallBack ()
804+
805+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
806+ defer inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
807+
808+ buildGradlePath := createGradleProject (t , "civcsproject" )
809+ projectDir := filepath .Dir (buildGradlePath )
810+ tests .CopyGitFixtureIntoProject (t , projectDir )
811+
812+ oldHomeDir := changeWD (t , projectDir )
813+ defer clientTestUtils .ChangeDirAndAssert (t , oldHomeDir )
814+
815+ runJfrogCli (t , "gradle" , "clean" , "publish" , "--build-name=" + buildName , "--build-number=" + buildNumber )
816+ require .NoError (t , artifactoryCli .Exec ("bp" , buildName , buildNumber ))
817+
818+ clientTestUtils .ChangeDirAndAssert (t , oldHomeDir )
819+
820+ var publishedBuildInfo * buildinfo.PublishedBuildInfo
821+ var found bool
822+ require .Eventually (t , func () bool {
823+ var biErr error
824+ publishedBuildInfo , found , biErr = tests .GetBuildInfo (serverDetails , buildName , buildNumber )
825+ return biErr == nil && found
826+ }, 30 * time .Second , 2 * time .Second )
827+
828+ serviceManager , err := utils .CreateServiceManager (serverDetails , 3 , 1000 , false )
829+ require .NoError (t , err )
830+
831+ count := tests .ValidateLocalGitVcsPropsOnBuildInfoArtifacts (t , serviceManager , publishedBuildInfo , tests .GradleRepo ,
832+ tests .VcsFixtureMainURL , tests .VcsFixtureMainRevision , tests .VcsFixtureMainBranch )
833+ assert .Greater (t , count , 0 )
834+
835+ cleanGradleTest (t )
836+ }
0 commit comments