|
|
@@ -12,6 +12,7 @@ import cn.seecoder.build.server.util.ServiceException;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.offbytwo.jenkins.JenkinsServer;
|
|
|
+import com.offbytwo.jenkins.client.JenkinsHttpClient;
|
|
|
import com.offbytwo.jenkins.model.*;
|
|
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
import org.dom4j.*;
|
|
|
@@ -19,8 +20,10 @@ import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -30,29 +33,26 @@ public class JenkinsApiImpl implements JenkinsApi {
|
|
|
|
|
|
private static final Logger logger = LoggerUtil.getLogger(JenkinsApiImpl.class);
|
|
|
|
|
|
- //private final ApplicationProperties properties;
|
|
|
+ private final ApplicationProperties properties;
|
|
|
|
|
|
private JenkinsServer server;
|
|
|
private JenkinsInternalApi jenkinsInternalApi;
|
|
|
|
|
|
@Autowired
|
|
|
- //public JenkinsApiImpl(ApplicationProperties properties, JenkinsInternalApi jenkinsInternalApi) {
|
|
|
-
|
|
|
- public JenkinsApiImpl(JenkinsInternalApi jenkinsInternalApi) {
|
|
|
- //this.properties = properties;
|
|
|
+ public JenkinsApiImpl(ApplicationProperties properties, JenkinsInternalApi jenkinsInternalApi) {
|
|
|
+ this.properties = properties;
|
|
|
this.jenkinsInternalApi = jenkinsInternalApi;
|
|
|
- server = new JenkinsServer(jenkinsInternalApi.getClient());
|
|
|
}
|
|
|
|
|
|
-// @PostConstruct
|
|
|
-// private void initialize() throws URISyntaxException {
|
|
|
-// ApplicationProperties.Jenkins jenkins = properties.getJenkins();
|
|
|
-// URI internalURI = new URI(jenkins.getInternalHost());
|
|
|
-// String username = jenkins.getUsername();
|
|
|
-// String token = jenkins.getToken();
|
|
|
-// JenkinsHttpClient client = new PoolingJenkinsHttpClient(internalURI, username, token);
|
|
|
-// server = new JenkinsServer(client);
|
|
|
-// }
|
|
|
+ @PostConstruct
|
|
|
+ private void initialize() throws URISyntaxException {
|
|
|
+ ApplicationProperties.Jenkins jenkins = properties.getJenkins();
|
|
|
+ URI internalURI = new URI(jenkins.getInternalHost());
|
|
|
+ String username = jenkins.getUsername();
|
|
|
+ String token = jenkins.getToken();
|
|
|
+ JenkinsHttpClient client = new PoolingJenkinsHttpClient(internalURI, username, token);
|
|
|
+ server = new JenkinsServer(client);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void createJob(String jobName, String configTemplate) throws ServiceException {
|