Jenkins插件开发-项目初始化

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

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

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  
    <localRepository>/Users/xxx/config/repository</localRepository>
     <pluginGroups>
    <pluginGroup>org.jenkins-ci.tools</pluginGroup>
  </pluginGroups>
  
  <proxies>
  </proxies>
  
  <servers>
  </servers>

  <mirrors>
    <mirror>
      <id>repo.jenkins-ci.org</id>
      <url>https://repo.jenkins-ci.org/public/</url>
      <mirrorOf>m.g.o-public</mirrorOf>
    </mirror>

    <mirror>
      <mirrorOf>m.g.o-public</mirrorOf>
      <url>http://repo.jenkins-ci.org/public</url>
      <id>jenkins-ci.org</id>
      <name>Jenkins CI Public</name>
    </mirror>

  </mirrors>


  <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>
</settings>

 

最终应该执行Maven构建命令:

mvn archetype:generate -Dfilter=io.jenkins.archetypes:plugin

 

 

过程:

原来执行命令为:

mvn hpi:create  或者 mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create   (但是实际执行会报错)
D:\Tools\jenkins-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:\Tools\jenkins-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:\Tools\jenkins-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:\Tools\jenkins-plugin\com.sza.sza
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:09 min
[INFO] Finished at: 2020-01-15T18:47:18+08:00
[INFO] ------------------------------------------------------------------------

jenkins提供给了我们三种 模板 :

Choose archetype:
# 空插件(Jenkins插件的框架)
1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.)
# 全局配置插件(具有POM和全局配置示例的Jenkins插件的框架)
2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton of a Jenkins plugin with a POM and an example piece of global configuration.)
# hello-world-plugin(带有POM的Jenkins插件的骨架和一个示例构建步骤)
3: remote -> io.jenkins.archetypes:hello-world-plugin (Skeleton of a Jenkins plugin with a POM and an example build step.)

 

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

D:\Tools\jenkins-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.dl
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.dl
Confirm properties configuration:
groupId: com.dl
artifactId: test
version: 1.0.0
package: com.dl
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: hello-world-plugin:1.6
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.dl
[INFO] Parameter: artifactId, Value: test
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: package, Value: com.dl
[INFO] Parameter: packageInPathFormat, Value: com/dl
[INFO] Parameter: package, Value: com.dl
[INFO] Parameter: version, Value: 1.0.0
[INFO] Parameter: groupId, Value: com.dl
[INFO] Parameter: artifactId, Value: test
[INFO] Project created from Archetype in dir: D:\Tools\jenkins-plugin\test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:39 min
[INFO] Finished at: 2020-01-16T13:47:25+08:00
[INFO] ------------------------------------------------------------------------

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

 

posted @ 2021-03-09 11:48  为你编程  阅读(345)  评论(0)    收藏  举报