sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key yum install jenkins 设置jenkins_home
source /etc/profile; ID=ps -ef | grep "jenkins.war" | grep -v "grep" | awk '{print $2}' ; kill -9 $ID rm -rf /usr/lib/jenkins/; mkdir /usr/lib/jenkins/; git clone git@172.20.5.36:atc-group/jenkins.git -b jenkins2.3 /usr/lib/jenkins/ nohup java -Dhudson.model.WorkspaceCleanupThread.disabled=true -jar /usr/lib/jenkins/jenkins.war >> /usr/lib/jenkins/jenkins.log 2>&1 &
#修改映射端口 #进入jenkins界面localhost:8080;系统管理-系统设置,设置jenkins-url为本机IP #tips如果页面无法访问,需要开启访问8080端口 iptables -A INPUT -p tcp --dport 8080 -j ACCEPT iptables -F
汉化插件: Locale plugin Localization:support Localization: Chinese (Simplified)
Notification plugin Pipeline: API Pipeline: Step API SCM API Plugin JUnit Credentials Plugin JDK Parameter Plugin
public static void main(String[] args) { try { JobWithDetails job = creatJenkinsJob(“jobName”,“xml_url”,“ip”); Map<String,String> map = new HashMap<>(); map.put(“name”,“1233211234567”); job.build(map,true); }catch (Exception e){ e.printStackTrace(); }
}
/**
* 创建一个目的主机上JobWithDetails对象
*
* @throws Exception
* @throws IOException
*/
public static JobWithDetails creatJenkinsJob(String jobName, String configUrl, String ip) throws Exception {
JobWithDetails build = null;
String url = getJenkinsUrl(ip);
try {
JenkinsServer server = new JenkinsServer(new URI(url));
URLConnection urlConnection = new URL(configUrl).openConnection();
HttpURLConnection connection = (HttpURLConnection) urlConnection;
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String current;
StringBuilder buildInfo = new StringBuilder();
while ((current = in.readLine()) != null) {
buildInfo.append(current);
buildInfo.append("\n");
}
server.createJob(jobName, buildInfo.toString(), true);
build = server.getJob(jobName);
} catch (IOException e) {
e.printStackTrace();
}
return build;
}
|