YAML参数以内联脚本

huangapple go评论77阅读模式
英文:

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: &#39;&#39;              
          inputs:
            workingDirectory: &#39;&#39;
            azureSubscription: 
            scriptType: &#39;pscore&#39;
            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 }}

huangapple
  • 本文由 发表于 2023年6月15日 21:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483203.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定