package com.ag.ci;

import com.offbytwo.jenkins.JenkinsServer;
import com.offbytwo.jenkins.model.*;

import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.util.List;
import java.util.Map;

public class AutoCItool {

    public void getjobs() throws  Exception{

        String username="";
        String password="";
        String url="****";
       // JenkinsServer jenkins=new JenkinsServer(new URI(url),username,password);
        JenkinsServer jenkins = new JenkinsServer(new URI("http://192.168.1.188:9999"), "admin", "anji6686");
        Map<String,Job> jobs=jenkins.getJobs();
        for(String keymame:jobs.keySet()){
            System.out.println(keymame);
        }
        JobWithDetails jobdetails=null;
//        Job job;
//        job=jobs.get("******");
//        jobdetails=job.details();
//        Build lastbuild=jobdetails.getLastBuild();
//        BuildWithDetails buildDetails=lastbuild.details();
//        if(buildDetails.isBuilding()){
//            System.out.println("最后一次构建还没完成，还在构建中");
//        }else{
//            System.out.println("最后一次构建已完成");
//        }
    }

    public void createjob() throws  Exception{

        File file = new File("/Users/shaoqiang/work/soft/config.xml");
        FileInputStream inputStream = new FileInputStream(file);
        byte[] bytes = new byte[0];
        bytes = new byte[inputStream.available()];
        inputStream.read(bytes);
        String str = new String(bytes);
        String jobXml="";
        JenkinsServer jenkins = new JenkinsServer(new URI("http://192.168.1.188:9999"), "admin", "anji6686");
        jenkins.createJob("pipeline_3hhh", str);
        List<Plugin> dataplugin=jenkins.getPluginManager().getPlugins();
      //  dataplugin.get(0).



    }

    public static void main(String args[]){

        AutoCItool autoCItool=new AutoCItool();
        try {
           // autoCItool.getjobs();
            autoCItool.createjob();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
