我试图将变量值(extraVars)从 Jenkins 传递给 Ansible 塔,但它只返回变量名而不是值。
我的詹金斯代码是
node ('windows'){
def zipFilename = "Windows file Zip (This value dynamically changed )"
stage('Deployment')
{
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
ansibleTower(
towerServer: 'Ansible_Tower',
jobTemplate: 'ANS- Test 1',
templateType: 'job',
importTowerLogs: true,
jobType: 'run',
removeColor: false,
verbose: false,
credential: 'cred',
inventory: 'Ansible_Test',
throwExceptionWhenFail: false,
extraVars: '''---
test_note: "${zipFilename}"'''
)
}
}}
[Ansible Tower 输出][1] [1]:https://i.stack.imgur.com/921ou.jpg
答案 0 :(得分:0)
您的代码很好,唯一的问题是参数没有被评估,因为在常规单引号 ('''
) 中不支持字符串插值,只有双引号 ("""
) 支持。
所以你只需要将 extraVars
使用的值改为双引号多行字符串:
extraVars: """---
test_note: '${zipFilename}'"""
如果您需要双引号,则可以使用以下内容:
extraVars: """---
test_note: \"${zipFilename}\""""