Java Code Examples for hudson.model.BuildListener#getLogger()

The following examples show how to use hudson.model.BuildListener#getLogger() . 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: DockerBuilderNewTemplate.java    From docker-plugin with MIT License 6 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
    final PrintStream llogger = listener.getLogger();
    final String dockerImage = dockerTemplate.getDockerTemplateBase().getImage();
    // Job must run as Admin as we are changing global cloud configuration here.
    build.getACL().checkPermission(Jenkins.ADMINISTER);
    for (Cloud c : Jenkins.getInstance().clouds) {
        if (c instanceof DockerCloud && dockerImage != null) {
            DockerCloud dockerCloud = (DockerCloud) c;
            if (dockerCloud.getTemplate(dockerImage) == null) {
                LOGGER.info("Adding new template: '{}', to cloud: '{}'", dockerImage, dockerCloud.name);
                llogger.println("Adding new template: '" + dockerImage + "', to cloud: '" + dockerCloud.name + "'");
                dockerCloud.addTemplate(dockerTemplate);
            }
        }
    }
    return true;
}
 
Example 2
Source File: NotifyQQ.java    From NotifyQQ with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws UnsupportedEncodingException {

    logger = listener.getLogger();

    Jenkins.getInstance();
    String jobURL = "";
    try {
        jobURL = build.getEnvironment(listener).expand("${JOB_URL}");
        logger.println("jobURL = " + jobURL);
    } catch (Exception e) {
        logger.println("tokenmacro expand error.");
    }

    String msg = "各位小伙伴,项目";
    msg += build.getFullDisplayName();
    if (build.getResult() == Result.SUCCESS) {
        msg += "编译成功!" + qqmessage;
    } else {
        msg += "编译失败了...";
        msg += "jenkins地址:" + jobURL;
    }

    msg = URLEncoder.encode(msg, "UTF-8");
    msg = msg.replaceAll("\\+", "_");

    for (int i = 0; i < qQNumbers.size(); i++) {
        QQNumber number = qQNumbers.get(i);
        send(GenerateMessageURL(number.GetUrlString(), msg));
    }

    return true;
}
 
Example 3
Source File: LambdaInvokePublisher.java    From aws-lambda-jenkins-plugin with MIT License 5 votes vote down vote up
public boolean perform(LambdaInvokeVariables lambdaInvokeVariables,AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
    if (lambdaInvokeVariables.getSuccessOnly() && build.getResult().isWorseThan(Result.SUCCESS)) {
        listener.getLogger().println("Build not successful, not invoking Lambda function: " + lambdaInvokeVariables.getFunctionName());
        return true;
    } else if (!lambdaInvokeVariables.getSuccessOnly() && build.getResult().isWorseThan(Result.UNSTABLE)) {
        listener.getLogger().println("Build failed, not invoking Lambda function: " + lambdaInvokeVariables.getFunctionName());
        return true;
    }
    try {
        LambdaInvokeVariables executionVariables = lambdaInvokeVariables.getClone();
        executionVariables.expandVariables(build.getEnvironment(listener));
        JenkinsLogger logger = new JenkinsLogger(listener.getLogger());
        LambdaClientConfig clientConfig = executionVariables.getLambdaClientConfig();
        InvokeConfig invokeConfig = executionVariables.getInvokeConfig();

        InvokeCallable invokeCallable = new InvokeCallable(listener, invokeConfig, clientConfig);

        LambdaInvocationResult invocationResult = launcher.getChannel().call(invokeCallable);

        if(!invocationResult.isSuccess()){
            build.setResult(Result.FAILURE);
        }

        for (Map.Entry<String,String> entry : invocationResult.getInjectables().entrySet()) {
            build.addAction(new LambdaOutputInjectionAction(entry.getKey(), entry.getValue()));
        }
        build.getEnvironment(listener);
        build.addAction(new LambdaInvokeAction(executionVariables.getFunctionName(), invocationResult.isSuccess()));
        return true;
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
 
Example 4
Source File: SemanticVersioningBuilder.java    From semantic-versioning-plugin with MIT License 4 votes vote down vote up
@Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
  	
      final PrintStream logger = listener.getLogger();
      
      SemanticVersioningCallable svc = new SemanticVersioningCallable();
      int buildNumber = -1;
      try {
      	buildNumber = Integer.parseInt(build.getEnvironment(TaskListener.NULL).get("BUILD_NUMBER"));
      } catch (Exception e) {
      }
      svc.setBuildNumber(buildNumber);
  	svc.setEnv(envVariable);
  	svc.setNamingStrategy(namingStrategy);
  	svc.setParser(parser);
  	svc.setUseBuildNumber(useJenkinsBuildNumber);
      svc.setWorkspace(build.getWorkspace());

logger.println("SemanticVersioning callable ... ");
  	SemanticVersioningResult svr = launcher.getChannel().call(svc);
  	if(svr.getLog()!=null) {
  		for(String s : svr.getLog()) {
  			for(String sx : s.split("[\\n\\r]+")) {
  				logger.println("SemanticVersioning REMOTE: "+sx);
  			}
  		}
  	}

  	if(svr.getVars()!=null) {
  		logger.println("SemanticVersioning adding injectVars action ...");
  		build.addAction(new InjectVersionVarsAction(svr.getVars()));
  		logger.println("SemanticVersioning adding injectVars action ... DONE!");
  	}
  	
  	
logger.println("SemanticVersioning callable ... DONE!");
  	
logger.println("SemanticVersioning writing to file: "+svr.getVersion()+" ... ");
  	writeVersionToFile(build, svr.getVersion());
logger.println("SemanticVersioning writing to file: "+svr.getVersion()+" ... DONE!");
  	
  	
      return true;
  }