Exemplo n.º 1
0
  private void setSvnCredential(CIJob job) throws JDOMException, IOException {
    S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential");
    try {
      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String credentialFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CREDENTIAL_XML;
      if (debugEnabled) {
        S_LOGGER.debug("credentialFilePath ... " + credentialFilePath);
      }
      File credentialFile = new File(credentialFilePath);

      SvnProcessor processor = new SvnProcessor(credentialFile);

      //			DataInputStream in = new DataInputStream(new FileInputStream(credentialFile));
      //			while (in.available() != 0) {
      //				System.out.println(in.readLine());
      //			}
      //			in.close();

      processor.changeNodeValue("credentials/entry//userName", job.getUserName());
      processor.changeNodeValue("credentials/entry//password", job.getPassword());
      processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName()));

      // jenkins home location
      String jenkinsJobHome = System.getenv(JENKINS_HOME);
      StringBuilder builder = new StringBuilder(jenkinsJobHome);
      builder.append(File.separator);

      processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML));
    } catch (Exception e) {
      S_LOGGER.error(
          "Entered into the catch block of CIManagerImpl.setSvnCredential "
              + e.getLocalizedMessage());
    }
  }
Exemplo n.º 2
0
  private void customizeNodes(ConfigProcessor processor, CIJob job)
      throws JDOMException, PhrescoException {

    // SVN url customization
    if (SVN.equals(job.getRepoType())) {
      S_LOGGER.debug("This is svn type project!!!!!");
      processor.changeNodeValue(SCM_LOCATIONS_REMOTE, job.getSvnUrl());
    } else if (GIT.equals(job.getRepoType())) {
      S_LOGGER.debug("This is git type project!!!!!");
      processor.changeNodeValue(SCM_USER_REMOTE_CONFIGS_URL, job.getSvnUrl());
      processor.changeNodeValue(SCM_BRANCHES_NAME, job.getBranch());
      // cloned workspace
    } else if (CLONED_WORKSPACE.equals(job.getRepoType())) {
      S_LOGGER.debug("Clonned workspace selected!!!!!!!!!!");
      processor.useClonedScm(job.getUsedClonnedWorkspace(), SUCCESSFUL);
    }

    // Schedule expression customization
    processor.changeNodeValue(TRIGGERS_SPEC, job.getScheduleExpression());

    // Triggers Implementation
    List<String> triggers = job.getTriggers();

    processor.createTriggers(TRIGGERS, triggers, job.getScheduleExpression());

    // if the technology is java stanalone and functional test , goal have to specified in post
    // build step only
    if (job.isEnablePostBuildStep() && FUNCTIONAL_TEST.equals(job.getOperation())) {
      // Maven command customization
      processor.changeNodeValue(GOALS, CI_FUNCTIONAL_ADAPT.trim());
    } else {
      // Maven command customization
      processor.changeNodeValue(GOALS, job.getMvnCommand());
    }

    // Recipients customization
    Map<String, String> email = job.getEmail();

    // Failure Reception list
    processor.changeNodeValue(
        TRIGGER_FAILURE_EMAIL_RECIPIENT_LIST, (String) email.get(FAILURE_EMAILS));

    // Success Reception list
    processor.changeNodeValue(
        TRIGGER_SUCCESS__EMAIL_RECIPIENT_LIST, (String) email.get(SUCCESS_EMAILS));

    // enable collabnet file release plugin integration
    if (job.isEnableBuildRelease()) {
      S_LOGGER.debug("Enablebling collabnet file release plugin ");
      processor.enableCollabNetBuildReleasePlugin(job);
    }

    // use clonned scm
    if (CLONED_WORKSPACE.equals(job.getRepoType())) {
      S_LOGGER.debug("using cloned workspace ");
      processor.useClonedScm(job.getUsedClonnedWorkspace(), SUCCESSFUL);
    }

    // clone workspace for future use
    if (job.isCloneWorkspace()) {
      S_LOGGER.debug("Clonning the workspace ");
      processor.cloneWorkspace(ALL_FILES, SUCCESSFUL, TAR);
    }

    // Build Other projects
    if (StringUtils.isNotEmpty(job.getDownStreamProject())) {
      S_LOGGER.debug("Enabling downstream project!!!!!!");
      processor.buildOtherProjects(job.getDownStreamProject());
    }

    // pom location specifier
    if (StringUtils.isNotEmpty(job.getPomLocation())) {
      S_LOGGER.debug("POM location changing " + job.getPomLocation());
      processor.updatePOMLocation(job.getPomLocation());
    }

    if (job.isEnablePostBuildStep()) {
      System.out.println("java stanalone technology with functional test enabled!!!!!!!");
      String mvnCommand = job.getMvnCommand();
      String[] ciAdapted =
          mvnCommand.split(CI_FUNCTIONAL_ADAPT); // java stanalone functional test alone
      for (String ciCommand : ciAdapted) {
        S_LOGGER.debug("ciCommand...." + ciCommand);
      }
      // iterate over loop
      processor.enablePostBuildStep(job.getPomLocation(), ciAdapted[1]);
    }

    if (job.isEnablePreBuildStep()) {
      System.out.println("java stanalone technology with functional test enabled!!!!!!!");
      // iterate over loop
      List<String> prebuildStepCommands = job.getPrebuildStepCommands();
      for (String prebuildStepCommand : prebuildStepCommands) {
        processor.enablePreBuildStep(job.getPomLocation(), prebuildStepCommand);
      }
    }
  }
Exemplo n.º 3
0
  private CIJobStatus configureJob(CIJob job, String jobType) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.createJob(CIJob job)");
    }
    try {
      cli = getCLI(job);
      List<String> argList = new ArrayList<String>();
      argList.add(jobType);
      argList.add(job.getName());

      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String configFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CONFIG_XML;
      if (debugEnabled) {
        S_LOGGER.debug("configFilePath ...  " + configFilePath);
      }

      File configFile = new File(configFilePath);
      ConfigProcessor processor = new ConfigProcessor(configFile);
      customizeNodes(processor, job);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (debugEnabled) {
        S_LOGGER.debug("argList " + argList.toString());
      }
      int result = cli.execute(argList, processor.getConfigAsStream(), System.out, baos);

      String message = "Job created successfully";
      if (result == -1) {
        byte[] byteArray = baos.toByteArray();
        message = new String(byteArray);
      }
      if (debugEnabled) {
        S_LOGGER.debug("message " + message);
      }
      // when svn is selected credential value has to set
      if (SVN.equals(job.getRepoType())) {
        setSvnCredential(job);
      }

      setMailCredential(job);
      return new CIJobStatus(result, message);
    } catch (IOException e) {
      throw new PhrescoException(e);
    } catch (JDOMException e) {
      throw new PhrescoException(e);
    } finally {
      if (cli != null) {
        try {
          cli.close();
        } catch (IOException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        } catch (InterruptedException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        }
      }
    }
  }