使用Jenkinsfile填充yaml时出现错误的变量格式

时间:2018-05-22 11:37:44

标签: jenkins groovy jenkins-pipeline

我有一个yml文件,我需要用Jenkins填充。

global:         
  name: 'my_name'
  code: 'my_code'

所以,我定义了Jenkins params:

string(name: 'NAME', defaultValue: 'Nightly Valid', description: 'Nightly Valid Name')
string(name: 'CODE', defaultValue: 'NIGHTLY', description: '')

在我的Jenkins文件中,我有:

           script {
               def filename = "configuration.yml"
               def yaml = readYaml file: filename

               // General data
               yaml.global.name = "${params.NAME}"
               yaml.global.code = "${params.CODE}"
               // ...

               sh "rm $filename"
               writeYaml file: filename, data: yaml

当我这样做时,我得到:

global:         
      name: '''my_name'''
      code: '''my_code'''

我该怎么办才能拥有:

global:         
      name: 'my_name'
      code: 'my_code'

1 个答案:

答案 0 :(得分:1)

" $ {params.NAME}" GStringImpl ,请尝试将其直接转换为字符串:"${params.NAME}".toString()