英文:
Yaml parameter to inline script
问题
你好,我认为我面临的问题可能是一个初学者的疑惑,但这里是问题:
我有一个被我的主要yaml调用的阶段yaml。阶段yaml有一个参数,我想在内联脚本中使用。
这是yaml(骨架)
```yaml
parameters:
- name: myParam
type: string
stages:
- stage:
dependsOn:
displayName:
pool:
name:
jobs:
- deployment:
displayName:
pool:
name:
environment:
name:
strategy:
runOnce:
deploy:
steps:
- template:
parameters:
azureServiceConnection:
subscriptionId:
- task: AzureCLI@2
displayName: ''
inputs:
workingDirectory: ''
azureSubscription:
scriptType: 'pscore'
scriptLocation: inlineScript
inlineScript: |
Write-Host //我想在这里打印它或像下一行这样分配给变量
$paramValue = //这里
如何在这里使用myParam?
<details>
<summary>英文:</summary>
Hello I think the problem I am facing might be a beginner doubt, but here it is:
I have a stage yaml which is called by my main yaml. Stage yaml has a parameter which I want to use in inline script.
Here is the yaml (skeleton)
parameters:
- name: myParam
type: string
stages:
- stage:
dependsOn:
displayName:
pool:
name:
jobs:-
deployment:
displayName:
pool:
name:
environment:
name:
strategy:
runOnce:
deploy:
steps:
- template:
parameters:
azureServiceConnection:
subscriptionId:- task: AzureCLI@2 displayName: '' inputs: workingDirectory: '' azureSubscription: scriptType: 'pscore' scriptLocation: inlineScript inlineScript: | Write-Host //I want to print it here or assign to a variable like next line $paramValue = //here
-
How can I use myParam here?
</details>
# 答案1
**得分**: 1
指定一个 `env` 块并将该值引用为环境变量。
例如:
```yaml
- task: AzureCLI@2
inputs:
inlineScript: |
Write-Host $env:FOO
env:
FOO: ${{ parameters.myParameter }}
英文:
Specify an env
block and reference the value as an environment variable.
i.e.
- task: AzureCLI@2
inputs:
inlineScript: |
Write-Host $env:FOO
env:
FOO: ${{ parameters.myParameter }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论