@@ -740,6 +740,79 @@ func TestBuildPublishWithOverwrite(t *testing.T) {
740740 cleanArtifactoryTest ()
741741}
742742
743+ func TestArtifactoryBuildPublishWithCollectEnvAndCollectGit (t * testing.T ) {
744+ initArtifactoryTest (t , "" )
745+ buildNumber := "12"
746+
747+ // Build collect env
748+ setEnvCallBack := clientTestUtils .SetEnvWithCallbackAndAssert (t , "DONT_COLLECT" , "foo" )
749+ defer setEnvCallBack ()
750+ setEnvCallBack = clientTestUtils .SetEnvWithCallbackAndAssert (t , "COLLECT" , "bar" )
751+ defer setEnvCallBack ()
752+
753+ oldHomeDir := os .Getenv (coreutils .HomeDir )
754+ createJfrogHomeConfig (t , true )
755+
756+ // Create .git folder for this test
757+ originalFolder := "buildaddgit_.git_suffix"
758+ baseDir , dotGitPath := coretests .PrepareDotGitDir (t , originalFolder , "testdata" )
759+ defer cleanBuildAddGitTest (t , baseDir , originalFolder , oldHomeDir , dotGitPath )
760+
761+ // Get path for build-add-git config file
762+ pwd , _ := os .Getwd ()
763+ configPath := filepath .Join (pwd , "testdata" , "buildaddgit_config.yaml" )
764+
765+ expectedVcsUrl := "https://github.com/jfrog/jfrog-cli-go.git"
766+ expectedVcsRevision := "b033a0e508bdb52eee25654c9e12db33ff01b8ff"
767+ expectedVcsBranch := "master"
768+ expectedVcsMessage := "TEST-4 - Adding text to file2.txt"
769+
770+ // Publish build info
771+ runRt (t , "bp" , tests .RtBuildName1 , buildNumber , "--collect-env" , "--collect-git-info" , "--dot-git-path" ,
772+ baseDir , "--git-config-file-path" , configPath , "--env-exclude=*password*;*psw*;*secret*;*key*;*token*;DONT_COLLECT" )
773+ publishedBuildInfo , found , err := tests .GetBuildInfo (serverDetails , tests .RtBuildName1 , buildNumber )
774+ if err != nil {
775+ assert .NoError (t , err )
776+ return
777+ }
778+ if ! found {
779+ assert .True (t , found , "build info was expected to be found" )
780+ return
781+ }
782+ buildInfo := publishedBuildInfo .BuildInfo
783+
784+ // validate env results
785+ // Make sure no sensitive data in build env
786+ for k := range buildInfo .Properties {
787+ assert .NotContains (t , k , "password" )
788+ assert .NotContains (t , k , "psw" )
789+ assert .NotContains (t , k , "secret" )
790+ assert .NotContains (t , k , "key" )
791+ assert .NotContains (t , k , "token" )
792+ assert .NotContains (t , k , "DONT_COLLECT" )
793+ }
794+ // Make sure "COLLECT" env appear in build env
795+ assert .Contains (t , buildInfo .Properties , "buildInfo.env.COLLECT" )
796+ assert .Empty (t , buildInfo .Modules , "Env collection should not add a new module to the build info" )
797+
798+ // Validate git results
799+ buildInfoVcsUrl := buildInfo .VcsList [0 ].Url
800+ buildInfoVcsRevision := buildInfo .VcsList [0 ].Revision
801+ buildInfoVcsBranch := buildInfo .VcsList [0 ].Branch
802+ buildInfoVcsMessage := buildInfo .VcsList [0 ].Message
803+ assert .Equal (t , expectedVcsRevision , buildInfoVcsRevision , "Wrong revision" )
804+ assert .Equal (t , expectedVcsUrl , buildInfoVcsUrl , "Wrong url" )
805+ assert .Equal (t , expectedVcsBranch , buildInfoVcsBranch , "Wrong branch" )
806+ assert .Equal (t , expectedVcsMessage , buildInfoVcsMessage , "Wrong Message" )
807+ assert .False (t , buildInfo .Issues == nil || len (buildInfo .Issues .AffectedIssues ) != 4 ,
808+ "Wrong issues number, expected 4 issues, received: %+v" , * buildInfo .Issues )
809+ assert .Empty (t , buildInfo .Modules , "Vcs collection should not add a new module to the build info" )
810+
811+ // Cleanup
812+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , tests .RtBuildName1 , artHttpDetails )
813+ cleanArtifactoryTest ()
814+ }
815+
743816func assertBuildNumberOccurrencesForGivenBuildNameAndNumber (t * testing.T , existingBuildInfo * buildinfo.BuildRuns ,
744817 expectedOccurrences int , found bool , buildNumber string , err error ) {
745818
0 commit comments