@@ -1247,3 +1247,98 @@ func TestContainerFatManifestPullWithSha(t *testing.T) {
12471247 }
12481248
12491249}
1250+
1251+ // TestDockerBuildPublishWithCIVcsProps tests that CI VCS properties are set on Docker artifacts
1252+ // when running build-publish in a CI environment (GitHub Actions).
1253+ func TestDockerBuildPublishWithCIVcsProps (t * testing.T ) {
1254+ cleanup := initDockerBuildTest (t )
1255+ defer cleanup ()
1256+
1257+ buildName := "docker-civcs-test"
1258+ buildNumber := "1"
1259+
1260+ // Setup GitHub Actions environment (uses real env vars on CI, mock values locally)
1261+ cleanupEnv , actualOrg , actualRepo := tests .SetupGitHubActionsEnv (t )
1262+ defer cleanupEnv ()
1263+
1264+ // Clean old build
1265+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
1266+ defer inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
1267+
1268+ // Extract hostname from ContainerRegistry
1269+ registryHost := * tests .ContainerRegistry
1270+ if parsedURL , err := url .Parse (registryHost ); err == nil && parsedURL .Host != "" {
1271+ registryHost = parsedURL .Host
1272+ }
1273+
1274+ // Construct image name
1275+ imageName := path .Join (registryHost , tests .OciLocalRepo , "test-civcs-docker" )
1276+ imageTag := imageName + ":v1"
1277+
1278+ // Create test workspace
1279+ workspace , err := filepath .Abs (tests .Out )
1280+ assert .NoError (t , err )
1281+ assert .NoError (t , fileutils .CreateDirIfNotExist (workspace ))
1282+
1283+ // Create simple Dockerfile
1284+ baseImage := path .Join (registryHost , tests .OciRemoteRepo , "alpine:latest" )
1285+ dockerfileContent := fmt .Sprintf (`FROM %s
1286+ CMD ["echo", "Hello from CI VCS test"]` , baseImage )
1287+
1288+ dockerfilePath := filepath .Join (workspace , "Dockerfile" )
1289+ assert .NoError (t , os .WriteFile (dockerfilePath , []byte (dockerfileContent ), 0644 ))
1290+
1291+ // Clean build before test
1292+ runJfrogCli (t , "rt" , "bc" , buildName , buildNumber )
1293+
1294+ // Run docker build with build-info
1295+ runJfrogCli (t , "docker" , "build" , "-t" , imageTag , "--push" , "-f" , dockerfilePath , "--build-name=" + buildName , "--build-number=" + buildNumber , workspace )
1296+
1297+ // Publish build info - should set CI VCS props on Docker layers
1298+ runRt (t , "build-publish" , buildName , buildNumber )
1299+
1300+ // Validate build info was published with artifacts
1301+ publishedBuildInfo , found , err := tests .GetBuildInfo (serverDetails , buildName , buildNumber )
1302+ if err != nil {
1303+ assert .NoError (t , err )
1304+ return
1305+ }
1306+ if ! found {
1307+ assert .True (t , found , "build info was expected to be found" )
1308+ return
1309+ }
1310+
1311+ // Create service manager for getting artifact properties
1312+ serviceManager , err := utils .CreateServiceManager (serverDetails , 3 , 1000 , false )
1313+ assert .NoError (t , err )
1314+
1315+ // Verify VCS properties on each artifact from build info
1316+ artifactCount := 0
1317+ for _ , module := range publishedBuildInfo .BuildInfo .Modules {
1318+ for _ , artifact := range module .Artifacts {
1319+ // Docker artifacts may have empty OriginalDeploymentRepo - use the known repo
1320+ repo := artifact .OriginalDeploymentRepo
1321+ if repo == "" {
1322+ repo = tests .OciLocalRepo
1323+ }
1324+ fullPath := repo + "/" + artifact .Path
1325+
1326+ props , err := serviceManager .GetItemProps (fullPath )
1327+ assert .NoError (t , err , "Failed to get properties for artifact: %s" , fullPath )
1328+ assert .NotNil (t , props , "Properties are nil for artifact: %s" , fullPath )
1329+
1330+ // Validate VCS properties
1331+ assert .Contains (t , props .Properties , "vcs.provider" , "Missing vcs.provider on %s" , artifact .Name )
1332+ assert .Contains (t , props .Properties ["vcs.provider" ], "github" , "Wrong vcs.provider on %s" , artifact .Name )
1333+
1334+ assert .Contains (t , props .Properties , "vcs.org" , "Missing vcs.org on %s" , artifact .Name )
1335+ assert .Contains (t , props .Properties ["vcs.org" ], actualOrg , "Wrong vcs.org on %s" , artifact .Name )
1336+
1337+ assert .Contains (t , props .Properties , "vcs.repo" , "Missing vcs.repo on %s" , artifact .Name )
1338+ assert .Contains (t , props .Properties ["vcs.repo" ], actualRepo , "Wrong vcs.repo on %s" , artifact .Name )
1339+
1340+ artifactCount ++
1341+ }
1342+ }
1343+ assert .Greater (t , artifactCount , 0 , "No artifacts in build info" )
1344+ }
0 commit comments