jfrog / project-examples

Small projects in universal build ecosystems to configure CI and Artifactory
1.01k stars 2.39k forks source link

Jenkins Scripted Pipeline (maven-example) leads to errors. It could be minimalistic. #255

Closed colathurv closed 3 years ago

colathurv commented 3 years ago

After working with https://github.com/jfrog/project-examples/blob/master/jenkins-examples/pipeline-examples/scripted-examples/maven-example/Jenkinsfile, I was hitting the following error:

org.codehaus.plexus.classworlds.launcher.Launcher -f maven-example/pom.xml clean install Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

I modified it to do the following. I have enunciated the placeholders using a string that anchors $$$

`node { //The value of Maven Tool Configuration should come from Global Tool configuration. It could be M3 def server = Artifactory.server "$$$NAME_OF_ARTFY_CONFIGURATION $$$" def rtMaven = Artifactory.newMavenBuild() def buildInfo

stage ('Clone') {
    git url: 'https://github.com/jfrog/project-examples.git'

}

stage ('Artifactory configuration') {
   //The value of Maven Tool Configuration should come from Global Tool configuration. It could be M3
    rtMaven.tool = "$$$NAME_OF_MAVEN_TOOL_CONFIGURATION$$$" 
    rtMaven.deployer releaseRepo: '$$$NAME_OF_YOUR_RELEASE_REPO$$$', snapshotRepo: 'NAME_OF_YOUR_SNAPSHOT_REPO', server: server
    buildInfo = Artifactory.newBuildInfo()
    buildInfo.env.capture = true
}

stage ('Exec Maven') {
    rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean install', buildInfo: buildInfo
}

stage ('Publish build info') {
    server.publishBuildInfo buildInfo
}

}`

Two differences from what you have and my script:

  1. rtResolver makes an implicit assumption that it can find the libs-release Repository in the Artifactory Server that it is deploying to. When I installed Artifactory I did not find this Repository. When I remove that line, maven pulls it from maven-central based on the pom.xml dependency.
  2. If we can create an Artifactory configuration and have the credentials stored in there, the code is more readable.

Otherwise this example you have come up with is outstanding in terms of how it demonstrates pushing a maven artifact to Artoifactory.

RobiNino commented 3 years ago

Hi @colathurv , Thanks a lot for your feedback.

  1. We encourage users to use the resolver against a virtual repository that may contain a local repo, and remote repositories (such as https://oss.jfrog.org/artifactory/jfrog-dependencies, jcenter, etc). The libs-release repository is usually created if the user creates the default repositories but I agree using a placeholder there will be clearer and easier to change.
  2. We try to diverse the Artifactory server creation between different examples to expose users to a variety of options. This example for instance uses a preconfigured server.
  3. Placeholders are defined in the example in a way that is convenient to add them as a pipeline parameter, which is why I believe anchoring with $$$ will be a bit problematic. Do you think we could make them stand out with more comments in the pipeline or perhaps a README attached to the example?

I created #260 following your feedback, please let me know what you think. Thanks

eyalbe4 commented 3 years ago

@colathurv, I'm closing this issue for now. Please let us know if you think we should add anything else. Also, feel free to contribute additions or ahcnges to the examples.