getting well formed output from ant - sshexec in groovy script

后端 未结 3 1853
忘掉有多难
忘掉有多难 2021-01-06 13:05

my problem is, that the output from the ant task alwas has some [ssh-exec] infotext at the beginning. can i suppress / disable that?

my code so far:

         


        
相关标签:
3条回答
  • 2021-01-06 13:16

    I tripped over the same issue in gradle and from there I had to change the way to access the property: According to the official gradle doc 3.3

    println ant.antProp
    println ant.properties.antProp
    println ant.properties['antProp']
    

    is the correct way to go.

    def ant = new AntBuilder()
    ant.sshexec(host: host,
                port: port,
                trust: true,
                username: username,
                password: password,
                command: 'ls',
                outputproperty: 'result')
    
    def result = ant.properties.'result'
    

    Hope this helps people in the same situation. Cheers

    0 讨论(0)
  • 2021-01-06 13:20

    You can save the raw output inside an Ant property:

    def ant = new AntBuilder()
    ant.sshexec(host: host,
                port: port,
                trust: true,
                username: username,
                password: password,
                command: 'ls',
                outputproperty: 'result')
    
    def result = ant.project.properties.'result'
    
    0 讨论(0)
  • 2021-01-06 13:27

    the problem is that outputproperty is not working properly (it does not set the ant variable).

    I often use trycatch from antcontrib to test if error occurs instead of reading return value.

    Example :

    <trycatch>
    <try>
          <sshexec host="@{host}" failonerror="true" username="${username}" password="${password}" timeout="${ssh.timeout}" command="@{command}" usepty="@{usepty}" trust="true" />
    </try>
    <catch>
          <echo>Service already stopped!</echo>
    </catch>
    </trycatch>
    
    0 讨论(0)
提交回复
热议问题