在Jenkins中使用StreamingMarkupBuilder()创建XML文件 [英] Creating XML file using StreamingMarkupBuilder() in Jenkins

查看:86
本文介绍了在Jenkins中使用StreamingMarkupBuilder()创建XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现在可以创建XML文件的常规方法.我已经使用groovyConsole进行了验证.但是,如果我在jenkinsfile中使用此代码段,则尽管工作成功完成,但仍未在工作空间中创建XML文件.

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.

问题:如何确保在工作空间中生成XML文件?我将在jenkinsfile的后续阶段中使用此XML

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

这是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)
      }
    }
  }

推荐答案

我在/目录中找到了该文件.由于我没有在文件编写器中输入任何路径.

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

更新: 对于分布式环境,这不是正确的解决方案.看来Java文件io操作只能在主服务器上工作,而不能在代理计算机上工作.

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.

这篇关于在Jenkins中使用StreamingMarkupBuilder()创建XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆