Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65484

Create standard convention for plugins' pom.xml

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I've been working on a script to read through all Jenkins instance plugins and retrieve their artifactId and version.  This is to populate a simple text file containing all plugins and versions to use in the install_plugins.sh script (part of Jenkins Configuration as Code).

       

      The script below is the closest I could get to parsing all the necessary info (this captures about 85% of our plugins).

       

      ```

      for f in `find /opt/jenkins/jenkins/plugins/ -name "pom.xml"`; do echo "$f" grep -B 4 -m 1 "<name>" $f > file_contents.txt
      ARTIFACT_ID=`grep -m 1 "<artifactId>" ./file_contents.txt | sed 's/.<artifactId>(.)<\/artifactId>./\1/g'` VERSION=`grep -m 1 "<version>" ./file_contents.txt | sed 's/.<version>(.)<\/version>./\1/g'`
      echo -e "${ARTIFACT_ID}:${VERSION}" >> $PLUGIN_FILE
      if [[ -z ${ARTIFACT_ID} || ${ARTIFACT_ID} == "plugin" || -z ${VERSION} ]]; then echo -e "WARNING: $f was not parsed correctly.  Please review." fi
      done

      ```

       

      Without a standard convention it is difficult to retrieve this accurately across all plugins, the above was the closest I could find.

       

      The plugins that were not parsed correctly could all be resolved similar to the below.

       

      FROM

      ```

      <artifactId>adoptopenjdk</artifactId>
      <version>1.4</version>
      <packaging>hpi</packaging>
      <properties>
      <java.level>8</java.level>
      <jenkins.version>2.164.3</jenkins.version>
      <wiremock.version>2.27.1</wiremock.version>
      <jetty.version>9.4.39.v20210325</jetty.version>
      </properties>
      <name>AdoptOpenJDK installer Plugin</name>

      ```

       

      TO

      ```

      <artifactId>adoptopenjdk</artifactId>
      <version>1.4</version>
      <packaging>hpi</packaging>

      <name>AdoptOpenJDK installer Plugin</name> 

      <properties>
      <java.level>8</java.level>
      <jenkins.version>2.164.3</jenkins.version>
      <wiremock.version>2.27.1</wiremock.version>
      <jetty.version>9.4.39.v20210325</jetty.version>
      </properties>
      ```

       

      The script relies on the <name> field and finds the artifactId and version preceding it to extract those values.  I'd like to suggest if the pom.xml can follow a standard convention which will help and if it could be added to the Style Guides docs.

       

      List of our current plugins that would need to be updated.

      adoptopenjdk/pom.xml

      build-blocker-plugin/pom.xml

      build-metrics/pom.xml

      build-timestamp/pom.xml

      calendar-view/pom.xml

      chromedriver/pom.xml

      config-file-provider/pom.xml

      email-ext-recipients-column/pom.xml

      global-variable-string-parameter/pom.xml

      jdk-tool/pom.xml

      log-parser/pom.xml

      mailmap-resolver/pom.xml

      matrix-combinations-parameter/pom.xml

      nodelabelparameter/pom.xml

      nvm-wrapper/pom.xml

      pipeline-model-declarative-agent/pom.xml

      postbuildscript/pom.xml

      publish-over/pom.xml

      sectioned-view/pom.xml

      sidebar-link/pom.xml

      token-macro/pom.xml

      preSCMbuildstep/pom.xml

      snakeyaml-api/pom.xml

      working-hours/pom.xml

      xml-job-to-job-dsl/pom.xml

      naginator/pom.xml

      sloccount/pom.xml

      rich-text-publisher-plugin/pom.xml

       

      I will open Pull Requests for this change unless someone can advise another workaround.  I could not find any existing plugins that would do this task.

        Attachments

          Activity

          Hide
          lkisac Len Isac added a comment -

          Yes, I was planning on creating those PRs but I agree especially at this point this would be too much overhead.  I was suggesting it to be a standard convention, but with the above workaround this is not necessary.  Thanks

          Show
          lkisac Len Isac added a comment - Yes, I was planning on creating those PRs but I agree especially at this point this would be too much overhead.  I was suggesting it to be a standard convention, but with the above workaround this is not necessary.  Thanks
          Hide
          ianw Ian Williams added a comment - - edited

          Glad the solution worked for you.

          Aside from the "it's a bad idea to parse XML via shell commands" (you can google it), what you were asking for would be e extremely impractical. Someone (you?) would have to create pull requests with the specific re-ordering of the XML fields, the PR have to be accepted, then a new plugin version released. Some plugins are clearly no longer maintained, so they'd never get that far. Then you'd have to install them so your script can pull the data to be useful. At that point you have a different list than what you started with, which probably defeats your intent (what do I have installed now?).

          There are lots of opportunities to contribute to improving the plugin experience. Suggest reviewing the Jenkins Developers group.

          Show
          ianw Ian Williams added a comment - - edited Glad the solution worked for you. Aside from the "it's a bad idea to parse XML via shell commands" (you can google it), what you were asking for would be e extremely impractical. Someone (you?) would have to create pull requests with the specific re-ordering of the XML fields, the PR have to be accepted, then a new plugin version released. Some plugins are clearly no longer maintained, so they'd never get that far. Then you'd have to install them so your script can pull the data to be useful. At that point you have a different list than what you started with, which probably defeats your intent (what do I have installed now?). There are lots of opportunities to contribute to improving the plugin experience. Suggest reviewing the Jenkins Developers group .
          Hide
          lkisac Len Isac added a comment -

          Thanks Ian Williams  

           

          The console script works well.  I would just need the id and version so I'm using the below.

           

          Jenkins.instance.pluginManager.plugins.sort(false) 
          { a, b -> a.getShortName().toLowerCase() <=> b.getShortName().toLowerCase()}.each { plugin ->
           println "${plugin.getShortName()}:${plugin.getVersion()}"
          }
          

           

          Plugin Installation Manager Tool seems to have been created with the same goal in mind.  I will review it as well and give it a try.  This ticket can be resolved I think for now since the multiple answers address this.  Thank you for your help.

           

          Show
          lkisac Len Isac added a comment - Thanks Ian Williams      The console script works well.  I would just need the id and version so I'm using the below.   Jenkins.instance.pluginManager.plugins.sort( false ) { a, b -> a.getShortName().toLowerCase() <=> b.getShortName().toLowerCase()}.each { plugin -> println "${plugin.getShortName()}:${plugin.getVersion()}" }   Plugin Installation Manager Tool seems to have been created with the same goal in mind.  I will review it as well and give it a try.  This ticket can be resolved I think for now since the multiple answers address this.  Thank you for your help.  
          Hide
          ianw Ian Williams added a comment - - edited

          Assuming you are trying to list the installed plugins (given the cmd : find /opt/jenkins/jenkins/plugins/ -name "pom.xml)

          You can find the list in the System Information page ${JENKINS_URL}/systemInfo, scroll to Plugins section.

          You can also run this, or a variant thereof form the script console:

          Jenkins.instance.pluginManager.plugins.sort(false) 
          { a, b -> a.getShortName().toLowerCase() <=> b.getShortName().toLowerCase()}.each { plugin ->
             println "${plugin.getShortName()}:${plugin.getVersion()} | ${plugin.getDisplayName()} "
          }
          

          Admittedly, the additional properties are not listed, but there may be more information available via PluginManager.MetadataCache

          Depending on your needs, you also may only want to specify the top-level plugins and not their dependencies.

          Are you aware of Plugin Installation Manager Tool for Jenkins ?

          Show
          ianw Ian Williams added a comment - - edited Assuming you are trying to list the installed plugins (given the cmd : find /opt/jenkins/jenkins/plugins/ -name "pom.xml ) You can find the list in the System Information page ${JENKINS_URL}/systemInfo , scroll to Plugins section. You can also run this, or a variant thereof form the script console: Jenkins.instance.pluginManager.plugins.sort( false ) { a, b -> a.getShortName().toLowerCase() <=> b.getShortName().toLowerCase()}.each { plugin -> println "${plugin.getShortName()}:${plugin.getVersion()} | ${plugin.getDisplayName()} " } Admittedly, the additional properties are not listed, but there may be more information available via PluginManager.MetadataCache Depending on your needs, you also may only want to specify the top-level plugins and not their dependencies. Are you aware of Plugin Installation Manager Tool for Jenkins ?

            People

            Assignee:
            lkisac Len Isac
            Reporter:
            lkisac Len Isac
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: