jfrog / jenkins-artifactory-plugin

Jenkins artifactory plugin
http://jenkins-ci.org/
116 stars 189 forks source link

publishBuildInfo gives cast exception #661

Open reece-oliver opened 2 years ago

reece-oliver commented 2 years ago

Describe the bug Upgraded to artifactory plugin to 3.16.1 from 3.14.2 and when I try to publishBuildInfo to my artifactory server I see the below error

org.jfrog.build.api.Artifact cannot be cast to org.jfrog.build.extractor.ci.Artifact

Stack trace

11:25:39      org.jfrog.build.extractor.ci.BuildInfo.ToBuild(BuildInfo.java:618)
11:25:39      org.jfrog.build.extractor.clientConfiguration.client.artifactory.services.PublishBuildInfo.<init>(PublishBuildInfo.java:29)
11:25:39      org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager.publishBuildInfo(ArtifactoryManager.java:140)
11:25:39      org.jfrog.build.extractor.retention.Utils.sendBuildAndBuildRetention(Utils.java:65)
11:25:39      org.jfrog.hudson.pipeline.common.BuildInfoDeployer.deploy(BuildInfoDeployer.java:87)
11:25:39      org.jfrog.hudson.pipeline.common.executors.PublishBuildInfoExecutor.execute(PublishBuildInfoExecutor.java:38)
11:25:39      org.jfrog.hudson.pipeline.scripted.steps.PublishBuildInfoStep$Execution.runStep(PublishBuildInfoStep.java:46)
11:25:39      org.jfrog.hudson.pipeline.scripted.steps.PublishBuildInfoStep$Execution.runStep(PublishBuildInfoStep.java:34)
11:25:39      org.jfrog.hudson.pipeline.ArtifactorySynchronousNonBlockingStepExecution.run(ArtifactorySynchronousNonBlockingStepExecution.java:54)
11:25:39      org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)

To Reproduce

  def server = Artifactory.server 'na-artifactory'
  def buildInfo = Artifactory.newBuildInfo()

  <blah blah stuff inbetween>

   server.publishBuildInfo(buildInfo)

Expected behavior It should publish the buildInfo to artifactory, it does this fine in artifactory plugin 3.14.2

Versions

Additional context Add any other context about the problem here.

fraz3alpha commented 2 years ago

I think we've worked out the cause of this - @reece-oliver 's code was using a different Builder class, and it was returning a list of objects of the wrong type:

// Artifactory plugin
import org.jfrog.build.api.builder.ArtifactBuilder
import org.jfrog.build.api.builder.DependencyBuilder

replaced with

import org.jfrog.build.extractor.builder.ArtifactBuilder
import org.jfrog.build.extractor.builder.DependencyBuilder

I don't know why the old one stopped working and the new one needed to be used - those two classes are very similar, if not identical, apart from the returned types, but something in the plugin meant the new one was needed after a certain point/version