You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jenkins Pipeline中跨作业传递变量entaClient至字符串参数

Hey there, let's fix that variable interpolation issue in your Jenkins Pipeline!

The core problem here is how Groovy handles string interpolation—only double-quoted strings will replace ${variable} with its actual value, while single-quoted strings treat everything as literal text. Your current code uses single quotes for taskFilterName and tasksGroup, so ${entaClient} isn't being substituted. Also, there's a missing closing quote in your tasksGroup parameter that would cause a syntax error.

Here's the corrected version of your stage:

stage('Restart the Enta API') {
    steps {
        script {
            if (params.hotReload.contains('Hot Reload')) {
                build(job: 'Hot Reload (utility)', 
                    parameters: [
                        string(name: 'region', value: params.region),
                        string(name: 'cluster', value: params.cluster),
                        string(name: 'taskFilterName', value: "enta-${entaClient}-dev-api-"),
                        string(name: 'tasksGroup', value: "enta-${entaClient}-dev-api-a,enta-${entaClient}-dev-api-b"),
                        string(name: 'containerInstanceIdsToStartOn', value: params.containerInstanceIdsToStartOn)
                    ]
                )
            }
        }
    }
}

What changed:

  1. Swapped single quotes for double quotes on taskFilterName and tasksGroup values. This triggers Groovy's string interpolation, so ${entaClient} will be replaced with the actual value of your variable.
  2. Fixed the missing closing quote in tasksGroup—your original code cut off mid-string, which would have caused the pipeline to fail immediately.
  3. Cleaned up the formatting a bit to make the parameter list easier to read (always a good practice for maintainability!).

Quick check:

Make sure entaClient is properly defined and accessible in this part of the pipeline. If it's set in an earlier stage or script block, confirm it's not scoped to a local context that this stage can't reach. If entaClient might be empty, you could add a quick validation step to avoid generating invalid filter/group names, but that's up to your specific use case.

内容的提问来源于stack exchange,提问作者eekfonky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:28:11