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

Create standard convention for plugins' pom.xml

XMLWordPrintable

      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.

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

              Created:
              Updated:
              Resolved: