using nonCPS and xml builder

16 views
Skip to first unread message

niristotle okram

unread,
Mar 20, 2017, 2:21:52 PM3/20/17
to jenkins...@googlegroups.com
Hi, 
i have forged the below pipeline workflow. The intent is to generate the XML file as a part of the pipeline and it will be used in the subsequent stages of the pipeline. I can invoke the pipeline successfully, but i dont find the XML generated in the workspace. I would expect the "file.XML" generated in the workspace. As you can see, i am not full fledge in groovy yet. 

How can i make sure that the file.xml is created in the workspace? If i execute the script ( without the class generateXML() )in a groovyconsole it works. 
Any idea on how to pass the values of the variable before triggering the job?

  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}}' ]]
  ]



////////////////


import groovy.xml.*

node('linux') {

//clear workspace 
deleteDir()

  stage('Checkout') {
                //stuff to checkout
  }

  /*
  This will generate the manifest xml in the workspace of the running job
  */

generateXML()


}



@NonCPS

generateXML() {
  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 writer = new FileWriter('file.xml')
  def builder = new StreamingMarkupBuilder()
  builder.encoding = 'UTF-8'
  writer << 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)
    }
  }
}








Reply all
Reply to author
Forward
0 new messages