wso2esb- 在迭代器中介器外部访问变量



基本上,在迭代器内部,我使用脚本(名称:setValue)中介设置了一些变量。 我正在尝试在迭代器之外的 Ruby 脚本中访问它们。

根据文档:如何在迭代器内部定义的迭代器外部访问属性中介器?

我尝试过不同的选项:

1)在Ruby脚本中,我尝试使用

$mc.get-property('Operation','githubhosturl1');  I am getting syntax error at operation.

2)在迭代器之外,我尝试使用属性访问它们

<property   expression="get-property('operation','githubhosturl')  name="githubhosturl1) 

在表达式处出错。

3)在Ruby脚本中,我尝试了:

$mc.get-property('githubhosturl1') - 空值返回

如何解决此问题?

我的代码 - 代理服务 - 我只粘贴了有问题的一小部分。 在 setValue 脚本中,我可以在控制台日志中打印值。

<Iterator>
-------
--------
-------
<script description="setValue" language="js"><![CDATA[var log = mc.getServiceLog(); 
            var tool =  mc.getProperty('toolList');
           if( tool == "github")
           {    
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('githubhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('gitassetid',vassetid.toString());
                var vbranch="qa";
                mc.setProperty('gitbranch',vbranch.toString());
           }
           if( tool == "dockercloud")
           {
                var vhosturl = mc.getProperty('catName');
                mc.setProperty('dockerhosturl',vhosturl.toString());
                var vassetid = mc.getProperty('assetidval');
                mc.setProperty('dockerid',vassetid.toString());
                var creid = mc.getProperty('jsondata');
                mc.setProperty('doccredid',creid.toString());
                var vprojName = mc.getProperty('projName');
                mc.setProperty('docproj',vprojName.toString());
           }]]></script>
        <property expression="get-property('githubhosturl')" name="githubhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('gitbranch')" name="gitbranch1" scope="operation" type="STRING"/>
        <property expression="get-property('gitassetid')" name="gitassetid1" scope="operation" type="STRING"/>
        <property expression="get-property('dockerhosturl')" name="dockerhosturl1" scope="operation" type="STRING"/>
        <property expression="get-property('doccredid')" name="doccredid1" scope="operation" type="STRING"/>
        <property expression="get-property('docproj')" name="docproj1" scope="operation" type="STRING"/>
    </sequence>
</target>
</iterate>
<script description="re" language="rb"><![CDATA[require 'erb'
     require 'erb'
     @giturl = $mc.getProperty('githubhosturl1');
      @gitbranch = $mc.getProperty('gitbranch1');
      @gitcredential = $mc.getProperty('gitassetid1');
      @dockerurl = $mc.getProperty('dockerhosturl1');
      @dockerCred = $mc.getProperty('doccredid1');
      @dockerprojectname = $mc.getProperty('docproj1');
      @template = File.read('C:WS02workspaceindex.txt.erb')
      OutTemplate = ERB.new(@template).result( binding )
      File.open('C:WS02workspaceJenkin.groovy',"w") do |f|
         f.puts OutTemplate
      end]]></script>

通过将迭代中的所有范围从"默认"更改为"操作",并使用get-property('operation',变量)在外部访问它们,然后将范围更改为"默认"

最新更新