最新的構建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:\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] ------------------------------------------------------------------------

 

  上面的配置中,由於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.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:\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插件的架構。

 

接下來,就可以順利的進行代碼開發了。開發過程,網上較多,在此不做贅述。

 

 

============我是底線=============

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM