• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

jenkins-client-java: 实现了绝大多数对Jenkins的操作(推荐使用 https://gitee.com/s ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

jenkins-client-java

开源软件地址:

https://gitee.com/jenkins-zh/jenkins-client-java

开源软件介绍:

Maven Central

jenkins-client-java

Java binding for the Jenkins client.

sonar

How to use it

Add the following dependency to the pom.xml file of your project:

<dependency>    <groupId>com.surenpi.ci</groupId>    <artifactId>jenkins.client.java</artifactId>    <version>1.0.0-20171217</version></dependency>

Example of get all jobs from jenkins

import com.surenpi.jenkins.client.Jenkins;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.List;/** * @author suren */public class Demo{    public static void main(String[] args) throws URISyntaxException, IOException    {        URI serverURI = new URI("http://localhost:8080/jenkins");        Jenkins jenkins = new Jenkins(serverURI, "admin", "admin");        Jobs jobMgr = jenkins.getJobs();        List<Job> allJobs = jobMgr.getAllJobs();        for(Job job : allJobs)        {            System.out.println(job.getName());        }    }}

Example of get all installed plugins from jenkins

import com.surenpi.jenkins.client.Jenkins;import com.surenpi.jenkins.client.plugin.Plugin;import com.surenpi.jenkins.client.plugin.Plugins;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.List;/** * @author suren */public class Demo{    public static void main(String[] args) throws URISyntaxException, IOException    {        URI serverURI = new URI("http://localhost:8080/jenkins");        Jenkins jenkins = new Jenkins(serverURI, "admin", "admin");        Plugins pluginMgr = jenkins.getPlugins();        List<Plugin> allInstalledPlugins = pluginMgr.getPluginManager().getPlugins();        for(Plugin plugin : allInstalledPlugins)        {            System.out.println(plugin.getShortName());        }    }}

Example of get all credentials from jenkins

import com.surenpi.jenkins.client.Jenkins;import com.surenpi.jenkins.client.credential.Credential;import com.surenpi.jenkins.client.credential.Credentials;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.Map;/** * @author suren */public class Demo{    public static void main(String[] args) throws URISyntaxException, IOException    {        URI serverURI = new URI("http://localhost:8080/jenkins");        Jenkins jenkins = new Jenkins(serverURI, "admin", "admin");        Credentials credentialMgr = jenkins.getCredentials();        Map<String, Credential> credentialMap = credentialMgr.list();        for(String key : credentialMap.keySet())        {            System.out.println(credentialMap.get(key).getDescription());        }    }}

Compile & Package

If you want to compile project, you can via mvn clean compile

If you want to package project and skip the junit test, you can via mvn clean package -DskipTest


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap