sitelink1 | https://www.jenkins.io/doc/book/using/remote-access-api |
---|---|
sitelink2 | https://github.com/cdancy/jenkins-rest |
sitelink3 |
private void requestGetService(String reqURL, Map<String, String> params, String authId, String authPass) throws IOException {
StringBuffer paramSb = new StringBuffer();
Iterator<String> paramIter = params.keySet().iterator();
String key = null;
String value = null;
int pCnt = 0;
while (paramIter.hasNext()) {
key = paramIter.next().toString();
value = params.get(key).toString();
if (pCnt > 0)
paramSb.append("&");
paramSb.append(key + "=" + value);
pCnt++;
}
URL url = new URL(reqURL + "?" + paramSb.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
if (authId != null && authPass != null) {
String encodedAuth = "Basic " + Base64Util.encode(authId + ":" + authPass);
conn.setRequestProperty("Authorization", encodedAuth);
}
BufferedReader brin = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String resStr = null;
StringBuffer resStrBuff = new StringBuffer();
try {
while ((resStr = brin.readLine()) != null) {
resStrBuff.append(resStr);
}
} finally {
if (brin != null) {
brin.close();
brin = null;
}
conn = null;
url = null;
resStr = null;
}
System.out.println("[requestUrlGet()]"+resStrBuff);
}
위 함수의 사용법
String reqURL = "http://[도메인]:[포트]/jenkins/job/[Job이름]/buildWithParameters";
String authId = "사용자ID";
String authPass = "사용자비번";
Map<String, String> params = new HashMap<String, String>();
params.put("token", "생성토큰");
params.put("param1", "value1");
params.put("param2", "value2");
this.requestGetService(reqURL, params, authId, authPass);
참고로 REST API 이외에도 Java Library도 있다 (필요성을 못느껴 아직 분석전)
URL :: https://www.jenkins.io/doc/book/using/remote-access-api/
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
8 |
Jenkins 백업 (Thinbackup)
![]() | 황제낙엽 | 2021.07.22 | 143 |
7 | Jenkins Restful API로 Job 과 Build 정보 조회 | 황제낙엽 | 2020.09.02 | 141 |
6 | Jenkins+TFS 연동 예제 | 황제낙엽 | 2020.09.01 | 141 |
» | [Jenkins] Java Sample with Jenkins Restful API | 황제낙엽 | 2020.08.12 | 195 |
4 |
Jenkins의 Restful API
![]() | 황제낙엽 | 2020.08.11 | 133 |
3 | jenkins에서 tfs에 접속하여 브랜치와 변경집합으로 소스를 다운로드하는 예제 | 황제낙엽 | 2020.08.11 | 136 |
2 |
(Jenkins) Application Server의 Continuous Integration 구성의 필요성
![]() | 황제낙엽 | 2020.05.20 | 93 |
1 |
Jenkins Rest API 사용기
![]() | 황제낙엽 | 2020.03.26 | 944 |