jenkins通过java客户端的方式进行触发构建

我爱海鲸 2025-11-03 17:18:56 暂无标签

简介jenkins、sdk

maven仓库:https://mvnrepository.com/artifact/io.github.cdancy/jenkins-rest/1.0.2

添加pom依赖:

<!-- https://mvnrepository.com/artifact/io.github.cdancy/jenkins-rest -->
<dependency>
    <groupId>io.github.cdancy</groupId>
    <artifactId>jenkins-rest</artifactId>
    <version>1.0.2</version>
</dependency>

使用:

JenkinsClient client = JenkinsClient.builder()
.endPoint("http://127.0.0.1:8080") // Optional. Defaults to http://127.0.0.1:8080
.credentials("admin:password") // Optional.  或者使用"admin:token"
.build();

SystemInfo systemInfo = client.api().systemApi().systemInfo();

        Map<String, List<String>> params = new HashMap<>();

       String finalJobName = "测试";

        // 触发参数化构建
        Integer queueId = client .api().jobsApi()
                .buildWithParameters(null, finalJobName, params )
                .value();

你好:我的2025