• 最新的构建Jenkins插件的方式


    记录瞬间

      最近想要了解一下Jenkins的插件如何开发,所以在网上找了一些资料,但是经过一番周折,发现之前的一些方法不能使用了,在此呢,根据自己的一些经历,简述一些开发Jenkins插件变化的地方。

      网上主要集中在构建Jenkins插件的框架上,前后的一些信息基本不变,比如:对Maven、Java版本的要求,修改settings.xml文件,后续开发代码的编写等基本都是不变的。

      JDK版本要求在1.6以上、Maven官方要求版本在3以上

      settings.xml文件需要配置如下:

    <settings>
      <pluginGroups>
        <pluginGroup>org.jenkins-ci.tools</pluginGroup>
      </pluginGroups>
    
      <profiles>
        <!-- Give access to Jenkins plugins -->
        <profile>
          <id>jenkins</id>
          <activation>
            <activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->
          </activation>
          <repositories>
            <repository>
              <id>repo.jenkins-ci.org</id>
              <url>https://repo.jenkins-ci.org/public/</url>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
              <id>repo.jenkins-ci.org</id>
              <url>https://repo.jenkins-ci.org/public/</url>
            </pluginRepository>
          </pluginRepositories>
        </profile>
      </profiles>
      <mirrors>
        <mirror>
          <id>repo.jenkins-ci.org</id>
          <url>https://repo.jenkins-ci.org/public/</url>
          <mirrorOf>m.g.o-public</mirrorOf>
        </mirror>
      </mirrors>
    </settings>
    

      

      修改的部分为执行Maven构建命令

      原来执行命令为:mvn hpi:create或者mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create   但是实际执行会报错

    D:Toolsjenkins-plugin>mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create
    [INFO] Scanning for projects...
    Downloading from central: https://repo.maven.apache.org/maven2/org/jenkins-ci/tools/maven-hpi-plugin/maven-metadata.xml
    Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/org/jenkins-ci/tools/maven-hpi-plugin/maven-metadata.xml
    Downloaded from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/org/jenkins-ci/tools/maven-hpi-plugin/maven-metadata.xml (3.4 kB at 2.1 kB/s)
    [INFO]
    [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] --- maven-hpi-plugin:3.11:create (default-cli) @ standalone-pom ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.652 s
    [INFO] Finished at: 2020-01-15T18:39:35+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.jenkins-ci.tools:maven-hpi-plugin:3.11:create (default-cli) on project standalone-pom: Unimplemented!
    [ERROR] hpi:create is obsolete. Instead use:
    [ERROR] ====
    [ERROR] mvn archetype:generate -Dfilter=io.jenkins.archetypes:
    [ERROR] ====
    [ERROR]
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    

      

    根据报错信息中的提示,需要执行的命令已经改为:mvn archetype:generate -Dfilter=io.jenkins.archetypes

    我们执行此条命令后,发现并没有实际的变化,只是下载了一些依赖包

    D:Toolsjenkins-plugin>mvn archetype:generate -Dfilter=io.jenkins.archetypes
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
    [INFO]
    [INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
    [INFO]
    [INFO]
    [INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
    [INFO] Generating project in Interactive mode
    [INFO] Your filter doesn't match any archetype, so try again with another value.
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 12.987 s
    [INFO] Finished at: 2020-01-15T18:43:30+08:00
    [INFO] ------------------------------------------------------------------------

    说明我们的操作只对了一部分,不是完全正确需要进一步的执行,

    实际需要执行的命令为:mvn archetype:generate -Dfilter=io.jenkins.archetypes:plugin

    D:Toolsjenkins-plugin>mvn archetype:generate -Dfilter=io.jenkins.archetypes:plugin
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
    [INFO]
    [INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
    [INFO]
    [INFO]
    [INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
    [INFO] Generating project in Interactive mode
    [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
    Choose archetype:
    1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.)
    2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a Jenkins plugin with a POM and an example piece of global configuration.)
    3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins plugin with a POM and an example build step.)
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
    Choose io.jenkins.archetypes:empty-plugin version:
    1: 1.0
    2: 1.1
    3: 1.2
    4: 1.3
    5: 1.4
    6: 1.5
    7: 1.6
    Choose a number: 7: 7
    Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/empty-plugin/1.6/empty-plugin-1.6.pom
    Downloaded from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/empty-plugin/1.6/empty-plugin-1.6.pom (717 B at 770 B/s)
    Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/archetypes-parent/1.6/archetypes-parent-1.6.pom
    Downloaded from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/archetypes-parent/1.6/archetypes-parent-1.6.pom (4.6 kB at 8.0 kB/s)
    Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/org/kohsuke/pom/21/pom-21.pom
    Downloaded from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/org/kohsuke/pom/21/pom-21.pom (6.1 kB at 11 kB/s)
    Downloading from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/empty-plugin/1.6/empty-plugin-1.6.jar
    Downloaded from repo.jenkins-ci.org: https://repo.jenkins-ci.org/public/io/jenkins/archetypes/empty-plugin/1.6/empty-plugin-1.6.jar (1.5 kB at 2.2 kB/s)
    [INFO] Using property: groupId = unused
    Define value for property 'artifactId': com.sza.sza
    Define value for property 'version' 1.0-SNAPSHOT: : 1.0.0
    [INFO] Using property: package = unused
    Confirm properties configuration:
    groupId: unused
    artifactId: com.sza.sza
    version: 1.0.0
    package: unused
     Y: : Y
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Archetype: empty-plugin:1.6
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: unused
    [INFO] Parameter: artifactId, Value: com.sza.sza
    [INFO] Parameter: version, Value: 1.0.0
    [INFO] Parameter: package, Value: unused
    [INFO] Parameter: packageInPathFormat, Value: unused
    [INFO] Parameter: version, Value: 1.0.0
    [INFO] Parameter: package, Value: unused
    [INFO] Parameter: groupId, Value: unused
    [INFO] Parameter: artifactId, Value: com.sza.sza
    [INFO] Project created from Archetype in dir: D:Toolsjenkins-plugincom.sza.sza
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 02:09 min
    [INFO] Finished at: 2020-01-15T18:47:18+08:00
    [INFO] ------------------------------------------------------------------------

      上面的配置中,由于groupID和package都没有进行设置,所以,在执行到    Y::   时,我们可以输入N来进行重新选择

    D:Toolsjenkins-plugin>mvn archetype:generate -Dfilter=io.jenkins.archetypes:plugin
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------< org.apache.maven:standalone-pom >-------------------
    [INFO] Building Maven Stub Project (No POM) 1
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO]
    [INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
    [INFO]
    [INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
    [INFO]
    [INFO]
    [INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
    [INFO] Generating project in Interactive mode
    [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
    Choose archetype:
    1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.)
    2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a Jenkins plugin with a POM and an example piece of global configuration.)
    3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins plugin with a POM and an example build step.)
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
    Choose archetype:
    1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.)
    2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a Jenkins plugin with a POM and an example piece of global configuration.)
    3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins plugin with a POM and an example build step.)
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 3
    Choose io.jenkins.archetypes:hello-world-plugin version:
    1: 1.1
    2: 1.2
    3: 1.3
    4: 1.4
    5: 1.5
    6: 1.6
    Choose a number: 6:
    [INFO] Using property: groupId = unused
    Define value for property 'artifactId':
    Define value for property 'version' 1.0-SNAPSHOT: :
    [INFO] Using property: package = io.jenkins.plugins.sample
    [WARNING] Archetype is not fully configured
    [INFO] Using property: groupId = unused
    Define value for property 'artifactId': 1
    [INFO] Using property: version = 1.0-SNAPSHOT
    [INFO] Using property: package = io.jenkins.plugins.sample
    Confirm properties configuration:
    groupId: unused
    artifactId: 1
    version: 1.0-SNAPSHOT
    package: io.jenkins.plugins.sample
     Y: : N
    Define value for property 'groupId' unused: : com.sza
    Define value for property 'artifactId': test
    Define value for property 'version' 1.0-SNAPSHOT: : 1.0.0
    Define value for property 'package' io.jenkins.plugins.sample: : com.sza
    Confirm properties configuration:
    groupId: com.sza
    artifactId: test
    version: 1.0.0
    package: com.sza
     Y: : Y
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Archetype: hello-world-plugin:1.6
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: com.sza
    [INFO] Parameter: artifactId, Value: test
    [INFO] Parameter: version, Value: 1.0.0
    [INFO] Parameter: package, Value: com.sza
    [INFO] Parameter: packageInPathFormat, Value: com/sza
    [INFO] Parameter: package, Value: com.sza
    [INFO] Parameter: version, Value: 1.0.0
    [INFO] Parameter: groupId, Value: com.sza
    [INFO] Parameter: artifactId, Value: test
    [INFO] Project created from Archetype in dir: D:Toolsjenkins-plugin	est
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 01:39 min
    [INFO] Finished at: 2020-01-16T13:47:25+08:00
    [INFO] ------------------------------------------------------------------------

    据此,可以在目录下查看到构建新的Jenkins插件的架构。

    接下来,就可以顺利的进行代码开发了。开发过程,网上较多,在此不做赘述。

    ============我是底线=============

  • 相关阅读:
    XMPP框架 微信项目开发之XMPP配置——MySQL数据库、MySQLworkbench、Openfire服务器的安装与配置
    Mac Mysql 启动关闭和重启命令、重新设置root密码 、 卸载
    CocoaPods安装使用 关键点
    CocoaPods的介绍、安装、使用和原理
    iOS 组件化架构漫谈
    将自己库添加Cocoapods支持
    Appium移动端自动化测试-安卓真机+模拟器启动
    Java学习第二十五天
    Java学习第二十四天
    Java学习第二十三天
  • 原文地址:https://www.cnblogs.com/wozijisun/p/12200184.html
Copyright © 2020-2023  润新知