Creating XML file using StreamingMarkupBuilder() in Jenkins

时光怂恿深爱的人放手 提交于 2019-12-12 05:14:29

问题


i have a groovy method that now creates XML files. I have verified it using the groovyConsole. But if i use this snippet in my jenkinsfile, the XML file is not seen to be created in the workspace, although the job completes successfully.

Question: how do i make sure that the XML file is generated in the workspace? I will be using this XML for subsequent stages in the jenkinsfile

Here is how the jenkinsfile looks like:

import groovy.xml.*

node('master') {

  deleteDir()

  stage('Checkout') {
   // checks out the code
  }

 generateXML("deploy.xml")  //This calls the method to generate the XML file


  //stage for packaging



  //Stage to Publish


  //Stage to Deploy


}


  @NonCPS
  def generateXML(file1) {

    println "Generating the manifest XML........"

    def workflows = [
    [ name: 'A', file: 'fileA', objectName: 'wf_A', objectType: 'workflow', sourceRepository: 'DEV2', folderNames: [ multifolder: '{{multifolderTST}}', multifolder2: '{{multifolderTST2}}' ]],

    [ name: 'B', file: 'fileB', objectName: 'wf_B', objectType: 'workflow', sourceRepository: 'DEV2', folderNames: [ multifolder3: '{{multifolderTST3}}', multifolder4: '{{multifolderTST4}}']]
    ]

     def builder = new StreamingMarkupBuilder()
    builder.encoding = 'UTF-8'
    new File(file1).newWriter() << builder.bind {
      mkp.xmlDeclaration()
      mkp.declareNamespace(udm :'http://www.w3.org/2001/XMLSchema')
      mkp.declareNamespace(powercenter:'http://www.w3.org/2001/XMLSchema')
      delegate.udm.DeploymentPackage(version:'$BUILD_NUMBER', application: "informaticaApp"){
        delegate.deployables {
          workflows.each { item ->
            delegate.powercenter.PowercenterXml(name:item.name, file:item.file) {
              delegate.scanPlaceholders(true)
              delegate.sourceRepository(item.sourceRepository)
              delegate.folderNameMap {
                item.folderNames.each { name, value ->
                  it.entry(key:name, value)
                }
              }
              delegate.objectNames {
                delegate.value(item.objectName)
              }
              delegate.objectTypes {
                delegate.value(item.objectType)
              }
            }
          }
        }
        delegate.dependencyResolution('LATEST')
        delegate.undeployDependencies(false)
      }
    }
  }

回答1:


I found the file in the / dir.. As i haven't entered any path in the filewriter.

UPDATE: this is not the right solution for a distributed env. It appears that the java file io operations only works in master and not in the agent machines.



来源:https://stackoverflow.com/questions/42915855/creating-xml-file-using-streamingmarkupbuilder-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!