com.offbytwo.jenkins.model.BuildResult Java Examples

The following examples show how to use com.offbytwo.jenkins.model.BuildResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JenkinsBuildResp.java    From seppb with MIT License 5 votes vote down vote up
public static JenkinsBuildResp apply(Integer number, BuildResult result) {
	JenkinsBuildResp jenkinsBuildResp = new JenkinsBuildResp();
	jenkinsBuildResp.setBuildVersion(number);
	jenkinsBuildResp.setShowSelect(false);
	jenkinsBuildResp.setStatus(Objects.equals(result, null) ? JenkinsBuildStatus.BUILDING :
			JenkinsBuildStatus.valueOf(result.name()));
	return jenkinsBuildResp;
}
 
Example #2
Source File: ThreadForBuildJob.java    From LuckyFrameClient with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void run(){
	JobBuildApi jobBuildApi=new JobBuildApi();
	BuildResult buildResult = jobBuildApi.buildAndGetResultForJobName(jobName);
	if(BuildResult.SUCCESS.equals(buildResult)){
		BuildingInitialization.THREAD_SUCCOUNT++;
	}
	BuildingInitialization.THREAD_COUNT--;        //���̼߳���--�����ڼ���߳��Ƿ�ȫ��ִ����
}
 
Example #3
Source File: ClassicJobApi.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public com.google.common.base.Function<WebDriver, Boolean> untilJobResultFunction(AbstractPipeline pipeline, BuildResult desiredResult) {
    return driver -> {
        try {
            JobWithDetails job = ClassicJobApi.this.jenkins.getJob(ClassicJobApi.this.getFolder(pipeline.getFolder(), false), pipeline.getName());
            BuildResult result = job.getLastBuild().details().getResult();
            return result == desiredResult;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    };
}
 
Example #4
Source File: JenkinsServerIntegration.java    From verigreen with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnBuildStatusForBuild() throws Exception {
    JobWithDetails job = server.getJobs().get("pr").details();
    BuildWithDetails build = job.getBuilds().get(0).details();
    assertEquals(BuildResult.SUCCESS, build.getResult());
    assertEquals("foobar", build.getParameters().get("REVISION"));
}
 
Example #5
Source File: JenkinsVerifier.java    From verigreen with Apache License 2.0 5 votes vote down vote up
@Override
public boolean stop(String jobName, String buildIdToStop) {
    //TODO: Remove unnecessary calls to Jenkins for stopping a Build. Try to minimize the number of calls.   
    boolean ans = false;
    try {
        VerigreenLogger.get().log(
                getClass().getName(),
                RuntimeUtils.getCurrentMethodName(),
                String.format("Stopping build (%s)", buildIdToStop));
        JobWithDetails job = CollectorApi.getJenkinsServer().getJob(jobName);
        Build buildToStop = job.getBuildByNumber(Integer.parseInt(buildIdToStop));
        if (buildIdToStop != null) {
            buildToStop.Stop();
            ans = buildToStop.details().getResult().equals(BuildResult.ABORTED);
        } else {
            VerigreenLogger.get().error(
                    getClass().getName(),
                    RuntimeUtils.getCurrentMethodName(),
                    String.format(
                            "There is no build number [%s] for job [%s]",
                            buildIdToStop,
                            jobName));
        }
    } catch (Throwable e) {
        VerigreenLogger.get().error(
                getClass().getName(),
                RuntimeUtils.getCurrentMethodName(),
                String.format("Failed to stop build [%s] for job [%s]", buildIdToStop, jobName),
                e);
    }
    
    return ans;
}
 
Example #6
Source File: BuildingInitialization.java    From LuckyFrameClient with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BuildResult buildingRun(String tastid) {
	try {
		String[] jobName = serverOperation.getBuildName(tastid);

		if (jobName != null) {
			ThreadPoolExecutor	threadExecute	= new ThreadPoolExecutor(jobName.length, 10, 3, TimeUnit.SECONDS,
					new ArrayBlockingQueue<>(1000),
		            new ThreadPoolExecutor.CallerRunsPolicy());
			
			LogUtil.APP.info("׼�������õIJ�����Ŀ���й��������Եȡ�������");
			for (String s : jobName) {
				BuildingInitialization.THREAD_COUNT++;   //���̼߳���++�����ڼ���߳��Ƿ�ȫ��ִ����
				threadExecute.execute(new ThreadForBuildJob(s));
			}
			
			//���̼߳��������ڼ���߳��Ƿ�ȫ��ִ����
			int k=0;
			while(BuildingInitialization.THREAD_COUNT!=0){
				k++;
				//��ȴ�����ʱ��45����
				if(k>2700){
					break;
				}
				Thread.sleep(1000);
			}
			threadExecute.shutdown();
			
			if(jobName.length!=THREAD_SUCCOUNT){
				LogUtil.APP.info("��������Ŀ{}���������ɹ�����Ŀ{}�����й��������쳣��ʧ��״̬��������鿴������־...",jobName.length,THREAD_SUCCOUNT);
				return BuildResult.FAILURE;
			}else{
				LogUtil.APP.info("�ܹ������ɹ�����Ŀ{}����ȫ�������ɹ���������鿴������־...",THREAD_SUCCOUNT);
			}
			
		} else {
			LogUtil.APP.info("��ǰ����û���ҵ���Ҫ��������Ŀ��");
		}
	} catch (Exception e) {
		LogUtil.APP.error("��Ŀ���������г����쳣", e);
		return BuildResult.UNSTABLE;
	}
	return BuildResult.SUCCESS;

}
 
Example #7
Source File: SlackJenkinsMessageRenderer.java    From benten with MIT License 4 votes vote down vote up
public static BentenSlackResponse renderJobDetailByJobName(JobWithDetails jobWithDetails) {

        BentenSlackResponse bentenSlackResponse= new BentenSlackResponse();
        try{
            if(jobWithDetails!=null){
                List<BentenSlackField> bentenSlackFields = new ArrayList<BentenSlackField>();
                List<BentenSlackAttachment> bentenSlackAttachments = new ArrayList<BentenSlackAttachment>();
                BentenSlackAttachment bentenSlackAttachment = new BentenSlackAttachment();

                bentenSlackResponse.setSlackText("Below is the Job details");
                SlackFormatter slackFormatter = SlackFormatter.create();
                slackFormatter.link(jobWithDetails.getUrl(),jobWithDetails.getDisplayName()).text(jobWithDetails.getDescription()).newline().newline();

                BuildResult buildResult = jobWithDetails.getLastBuild().details().getResult();
                if(buildResult!=null) {
                    bentenSlackFields.add(new BentenSlackField("Last Build Status", buildResult.toString(), true));
                    if(buildResult.equals(BuildResult.SUCCESS))
                        bentenSlackAttachment.setColor("GOOD");
                    else if(buildResult.equals(BuildResult.FAILURE))
                        bentenSlackAttachment.setColor("DANGER");
                    else if(buildResult.equals(BuildResult.UNSTABLE))
                        bentenSlackAttachment.setColor("WARNING");
                    else
                        bentenSlackAttachment.setColor("WARNING");
                }
                else {
                    bentenSlackFields.add(new BentenSlackField("Last Build Status", "INPROGRESS", true));
                }
                bentenSlackFields.add(new BentenSlackField("Last Build",Integer.toString(jobWithDetails.getLastBuild().getNumber()),true));
                bentenSlackFields.add(new BentenSlackField("Last Successful Build",Integer.toString(jobWithDetails.getLastSuccessfulBuild().getNumber()),true));
                bentenSlackFields.add(new BentenSlackField("Last Failed Build",Integer.toString(jobWithDetails.getLastFailedBuild().getNumber()),true));
                bentenSlackFields.add(new BentenSlackField("Is in Queue",Boolean.toString(jobWithDetails.isInQueue()),true));
                bentenSlackFields.add(new BentenSlackField("Is Buildable",Boolean.toString(jobWithDetails.isBuildable()),true));

                bentenSlackAttachment.setText(slackFormatter.build());
                bentenSlackAttachment.setBentenSlackFields(bentenSlackFields);
                bentenSlackAttachments.add(bentenSlackAttachment);

                bentenSlackResponse.setBentenSlackAttachments(bentenSlackAttachments);
            }
            else {
                bentenSlackResponse.setSlackText("Errr!! The Jenkins Job was not found.");
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new BentenJenkinsException(e.getMessage());
        }
        return bentenSlackResponse;
    }