因此,我正在处理一堆管道,并且使用YML模板设置了所有内容。但是,我很难在模板步骤内部扩展受保护的变量。我已经尝试通过正常方式传递受保护变量,但它们似乎没有扩展。然后,我尝试使用一个变量组,据说我可以直接在模板内引用。我说,因为微软在他们的网站上说了 https://learn.microsoft.com/en-us/azure/devops/pipelines/library/library/variable/variable-groups?view = azure-devops& tabs = tabs = yaml
:还可以在模板变量中引用一个变量组。
variables:
- group: my-variable-group
但是,每当我在模板代码中包括变量
部分时,Azure DevOps在运行管道之前在解析YML时立即抱怨它。它吐出以下消息:
/ymls /my-template@my-repo(行:1,col:1):意外的值'变量'
我不坚持使用变量组,我只想拥有我的受保护变量在我的YML模板中扩展。有人知道该怎么做吗???
任何帮助都非常感谢!
So I'm working on a bunch of pipelines and I've set everything up using yml templates. However I struggle with getting protected variable expanded inside of my template steps. I've tried passing in the protected variables by normal means, but they seem to not get expanded. Then I tried using a variable group, which I supposedly can directly reference inside of templates. I say supposedly, because Microsoft says so on their website https://learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml:
"You can also reference a variable group in a template. In the template variables.yml, the group my-variable-group is referenced. The variable group includes a variable named myhello."
variables:
- group: my-variable-group
However, whenever I include a variables
section into my template code, Azure DevOps immediately complains about it when parsing the yml, before running the pipeline. It spits out the following message:
/ymls/my-template@my-repo (Line: 1, Col: 1): Unexpected value 'variables'
I don't insist on using variable groups, I just want to have my protected variables expanded in my yml template. Does anybody know how to do that???
Any help greatly appreciated!
发布评论
评论(2)
您应该在主管道上而不是在模板中定义变量组。然后您可以调用模板并使用您定义的变量。
例如,假设您有一个调用 template.yml 的 main.yml
您应该在
main.yml
上定义以下变量组并调用template.yml 上的变量
https://thomasthornton.cloud/2021/09/02/referencing-variable-groups-in-azure-devops-pipeline-templates/
You should define your variable group on your main pipeline and not in the template. Then you can call your template and use the variable that you defined.
For example lets say that you have your main.yml which calls template.yml
You should define the below variable group on
main.yml
And call the variable on your template.yml
https://thomasthornton.cloud/2021/09/02/referencing-variable-groups-in-azure-devops-pipeline-templates/
终于想通了。感谢@GeralexGR。事实证明,当您在主管道 yml 中引用变量组时,您会自动在模板 yml 中访问它。但对于正常的脚本步骤,您仍然必须显式地传递它。
然后它看起来……像这样:
main-pipeline.yml:
my-template.yml:
Finally figured it out. Thanks to @GeralexGR. Turns out, when you reference a variable group in the main pipeline yml, you automatically have access to it in the template yml. But for normal script steps you still have to pass it in explicitly.
It then looks s.th. like this:
main-pipeline.yml:
my-template.yml: