一、环境准备
- 安装jdk1.8
- 安装maven3,需要添加环境变量%MAVEN_HOME%
- 修改maven仓配置
修改%MAVEN_HOME%\conf\settings.xml内容,包括修改本地仓库位置,指定镜像地址等
<settings>
<pluginGroups>
<pluginGroup>org.jenkins-ci.tools</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>jenkins</id>
<activation>
<activeByDefault>true</activeByDefault>
</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>
<localRepository>D:\maven\apache-maven-3.5.0\repository\</localRepository>
</settings>
- 搭建一个jelly服务器
为了测试更接近真实环境,将做好的插件放到另一个jetty里,来测试效果。
jelly相关知识:http://cwqcwq.iteye.com/blog/798102
下载jelly:http://www.eclipse.org/jetty/download.html
下载jenkins.war:http://mirrors.jenkins.io/war-stable/
把jenkins.war包复制到jetty的webapps下面
在jetty的webapps下面新建jenkins.xml文件,文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/jenkins</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/jenkins.war</Set>
<Get name="securityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Jenkins Realm</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
</New>
</Set>
</Get>
</Configure>
启动jetty服务器,在jetty的安装目录下执行:
java -jar start.jar
访问jenkins:
http://localhost:8080/jenkins/
二、生成一个jenkins插件
# 创建一个插件
mvn archetype:generate -Dfilter=io.jenkins.archetypes:
# 生成.hpi插件并存到本地仓库中
mvn install
# 只生成.hpi插件,不存到本地仓库
mvn package
# 转为eclipse开发环境
mvn eclipse:eclipse
jenkins源码下载:https://github.com/jenkinsci/jenkins
参考资料
https://www.ibm.com/developerworks/cn/java/j-lo-jenkins-plugin/index.html
https://www.cnblogs.com/kingzzm/archive/2013/09/14/3321715.html
https://segmentfault.com/a/1190000008939662
http://blog.csdn.net/littleatp2008/article/details/7001793
网友评论