使用jenkins管道中的returnStdout将局部变量传递给批处理

问题描述 投票:1回答:2

当我尝试在批处理命令中替换date_append变量时,如下所示,它没有完全检索日期,而是显示为快照 - $ {date_append} .onp

确切的问题在哪里?

 stage('test') {
        steps {
                script
                {
                    date_append= "${new Date().format('yyyyMMdd_hhmmss')}"
                    echo "${date_append}"

                    issue=bat(label: '', returnStdout: true, script: '''echo off
             "C:\\Desktop\\eme.exe" /v 
         /source:SYS/dbname@localhost:port/env{test} AS SYSDBA 
        /target:C:\\desktop\\file-${date_append}.xml{test}  
       /scriptfile:C:\\script\\oldscript.sql
        @IF  %ERRORLEVEL% NEQ 61 (
   @echo "issue is FALSE"
  )''')
              }     
           }
       }
batch-file jenkins-pipeline
2个回答
4
投票

要在goovy中使用shell脚本中的变量,你需要使用G字符串,这是qazxsw poi而不是qazxsw poi

所以你的代码只需要交换"用于',并且要么逃避你当前使用的''',要么将它们交换为""",(下面我已经交换并转义你的双引号用于举例目的):

"

有关G弦的更多阅读,请参阅:qazxsw poi


0
投票

这对我有用!!!

'
© www.soinside.com 2019 - 2024. All rights reserved.