private void createConfigFile(String repository,File config){
  try {
    DocumentBuilderFactory docFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder=docFactory.newDocumentBuilder();
    Document doc=docBuilder.newDocument();
    Element rootElement=doc.createElement("project");
    doc.appendChild(rootElement);
    Element actions=doc.createElement("actions");
    rootElement.appendChild(actions);
    Element description=doc.createElement("description");
    rootElement.appendChild(description);
    Element keepDependencies=doc.createElement("keepDependencies");
    keepDependencies.appendChild(doc.createTextNode("false"));
    rootElement.appendChild(keepDependencies);
    Element properties=doc.createElement("properties");
    rootElement.appendChild(properties);
    Element scm=doc.createElement("scm");
    if (repository.equals("")) {
      scm.setAttribute("class","hudson.scm.NullSCM");
      rootElement.appendChild(scm);
    }
 else {
      scm.setAttribute("class","hudson.plugins.git.GitSCM");
      scm.setAttribute("plugin","git@2.4.4");
      Element configVersion=doc.createElement("configVersion");
      configVersion.appendChild(doc.createTextNode("2"));
      scm.appendChild(configVersion);
      Element userRemoteConfigs=doc.createElement("userRemoteConfigs");
      Element userRemoteConfig=doc.createElement("hudson.plugins.git.UserRemoteConfig");
      userRemoteConfigs.appendChild(userRemoteConfig);
      scm.appendChild(userRemoteConfigs);
      Element branches=doc.createElement("branches");
      Element branchSpec=doc.createElement("hudson.plugins.git.BranchSpec");
      Element name=doc.createElement("name");
      name.appendChild(doc.createTextNode("*/master"));
      branchSpec.appendChild(name);
      branches.appendChild(branchSpec);
      scm.appendChild(branches);
      Element doGenerateSubmoduleConfigurations=doc.createElement("doGenerateSubmoduleConfigurations");
      doGenerateSubmoduleConfigurations.appendChild(doc.createTextNode("false"));
      scm.appendChild(doGenerateSubmoduleConfigurations);
      Element browser=doc.createElement("browser");
      browser.setAttribute("class","hudson.plugins.git.browser.GitLab");
      Element url=doc.createElement("url");
      url.appendChild(doc.createTextNode(repository));
      browser.appendChild(url);
      Element version=doc.createElement("version");
      version.appendChild(doc.createTextNode("8.7"));
      browser.appendChild(version);
      scm.appendChild(browser);
      Element submoduleCfg=doc.createElement("submoduleCfg");
      submoduleCfg.setAttribute("class","list");
      scm.appendChild(submoduleCfg);
      Element extensions=doc.createElement("extensions");
      scm.appendChild(extensions);
    }
    rootElement.appendChild(scm);
    Element canRoam=doc.createElement("canRoam");
    canRoam.appendChild(doc.createTextNode("true"));
    rootElement.appendChild(canRoam);
    Element disabled=doc.createElement("disabled");
    disabled.appendChild(doc.createTextNode("false"));
    rootElement.appendChild(disabled);
    Element blockBuildWhenDownstreamBuilding=doc.createElement("blockBuildWhenDownstreamBuilding");
    blockBuildWhenDownstreamBuilding.appendChild(doc.createTextNode("false"));
    rootElement.appendChild(blockBuildWhenDownstreamBuilding);
    Element blockBuildWhenUpstreamBuilding=doc.createElement("blockBuildWhenUpstreamBuilding");
    blockBuildWhenUpstreamBuilding.appendChild(doc.createTextNode("false"));
    rootElement.appendChild(blockBuildWhenUpstreamBuilding);
    Element triggers=doc.createElement("triggers");
    rootElement.appendChild(triggers);
    Element concurrentBuild=doc.createElement("concurrentBuild");
    concurrentBuild.appendChild(doc.createTextNode("false"));
    rootElement.appendChild(concurrentBuild);
    Element builders=doc.createElement("builders");
    rootElement.appendChild(builders);
    Element publishers=doc.createElement("publishers");
    rootElement.appendChild(publishers);
    Element buildWrappers=doc.createElement("buildWrappers");
    rootElement.appendChild(buildWrappers);
    TransformerFactory transformerFactory=TransformerFactory.newInstance();
    Transformer transformer=transformerFactory.newTransformer();
    DOMSource source=new DOMSource(doc);
    StreamResult result=new StreamResult(config);
    transformer.transform(source,result);
  }
 catch (  Exception e) {
    logger.error(repository + ", " + config,e);
  }
}

private void createConfigFile ( String repository , File config ) { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder docBuilder = docFactory . newDocumentBuilder ( ) ; Document doc = docBuilder . newDocument ( ) ; Element rootElement = doc . createElement ( "project" ) ; doc . appendChild ( rootElement ) ; Element actions = doc . createElement ( "actions" ) ; rootElement . appendChild ( actions ) ; Element description = doc . createElement ( "description" ) ; rootElement . appendChild ( description ) ; Element keepDependencies = doc . createElement ( "keepDependencies" ) ; keepDependencies . appendChild ( doc . createTextNode ( "false" ) ) ; rootElement . appendChild ( keepDependencies ) ; Element properties = doc . createElement ( "properties" ) ; rootElement . appendChild ( properties ) ; Element scm = doc . createElement ( "scm" ) ; if ( repository . equals ( "" ) ) { scm . setAttribute ( "class" , "hudson.scm.NullSCM" ) ; rootElement . appendChild ( scm ) ; } else { scm . setAttribute ( "class" , "hudson.plugins.git.GitSCM" ) ; scm . setAttribute ( "plugin" , "git@2.4.4" ) ; Element configVersion = doc . createElement ( "configVersion" ) ; configVersion . appendChild ( doc . createTextNode ( "2" ) ) ; scm . appendChild ( configVersion ) ; Element userRemoteConfigs = doc . createElement ( "userRemoteConfigs" ) ; Element userRemoteConfig = doc . createElement ( "hudson.plugins.git.UserRemoteConfig" ) ; userRemoteConfigs . appendChild ( userRemoteConfig ) ; scm . appendChild ( userRemoteConfigs ) ; Element branches = doc . createElement ( "branches" ) ; Element branchSpec = doc . createElement ( "hudson.plugins.git.BranchSpec" ) ; Element name = doc . createElement ( "name" ) ; name . appendChild ( doc . createTextNode ( "*/master" ) ) ; branchSpec . appendChild ( name ) ; branches . appendChild ( branchSpec ) ; scm . appendChild ( branches ) ; Element doGenerateSubmoduleConfigurations = doc . createElement ( "doGenerateSubmoduleConfigurations" ) ; doGenerateSubmoduleConfigurations . appendChild ( doc . createTextNode ( "false" ) ) ; scm . appendChild ( doGenerateSubmoduleConfigurations ) ; Element browser = doc . createElement ( "browser" ) ; browser . setAttribute ( "class" , "hudson.plugins.git.browser.GitLab" ) ; Element url = doc . createElement ( "url" ) ; url . appendChild ( doc . createTextNode ( repository ) ) ; browser . appendChild ( url ) ; Element version = doc . createElement ( "version" ) ; version . appendChild ( doc . createTextNode ( "8.7" ) ) ; browser . appendChild ( version ) ; scm . appendChild ( browser ) ; Element submoduleCfg = doc . createElement ( "submoduleCfg" ) ; submoduleCfg . setAttribute ( "class" , "list" ) ; scm . appendChild ( submoduleCfg ) ; Element extensions = doc . createElement ( "extensions" ) ; scm . appendChild ( extensions ) ; } rootElement . appendChild ( scm ) ; Element canRoam = doc . createElement ( "canRoam" ) ; canRoam . appendChild ( doc . createTextNode ( "true" ) ) ; rootElement . appendChild ( canRoam ) ; Element disabled = doc . createElement ( "disabled" ) ; disabled . appendChild ( doc . createTextNode ( "false" ) ) ; rootElement . appendChild ( disabled ) ; Element blockBuildWhenDownstreamBuilding = doc . createElement ( "blockBuildWhenDownstreamBuilding" ) ; blockBuildWhenDownstreamBuilding . appendChild ( doc . createTextNode ( "false" ) ) ; rootElement . appendChild ( blockBuildWhenDownstreamBuilding ) ; Element blockBuildWhenUpstreamBuilding = doc . createElement ( "blockBuildWhenUpstreamBuilding" ) ; blockBuildWhenUpstreamBuilding . appendChild ( doc . createTextNode ( "false" ) ) ; rootElement . appendChild ( blockBuildWhenUpstreamBuilding ) ; Element triggers = doc . createElement ( "triggers" ) ; rootElement . appendChild ( triggers ) ; Element concurrentBuild = doc . createElement ( "concurrentBuild" ) ; concurrentBuild . appendChild ( doc . createTextNode ( "false" ) ) ; rootElement . appendChild ( concurrentBuild ) ; Element builders = doc . createElement ( "builders" ) ; rootElement . appendChild ( builders ) ; Element publishers = doc . createElement ( "publishers" ) ; rootElement . appendChild ( publishers ) ; Element buildWrappers = doc . createElement ( "buildWrappers" ) ; rootElement . appendChild ( buildWrappers ) ; TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; DOMSource source = new DOMSource ( doc ) ; StreamResult result = new StreamResult ( config ) ; transformer . transform ( source , result ) ; } catch ( Exception e ) { logger . error ( repository + ", " + config , e ) ; } }
create a config file of project for initialization in jenkins
