最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can I reference a lookup table in a DevOps pipeline? - Stack Overflow

programmeradmin1浏览0评论

I have an Azure DevOps pipeline which has 2 user entered variables ProductCode (a short string like "PROD001") and ProductId (a guid associated with that ProductCode).

Currently, when someone is running the pipeline, they need to enter the ProductCode, then go look to a separate document to manually find the ProductId for that code and copy and paste it back into the pipeline field.

Is it possible to store that table somewhere so the user only needs to enter the ProductCode and a pipeline action can look up the Id? It needs to be easily accessible so DevOps users can add new products as required (e.g. not having to edit a powershell script or a text file stored in the code branch)

I have an Azure DevOps pipeline which has 2 user entered variables ProductCode (a short string like "PROD001") and ProductId (a guid associated with that ProductCode).

Currently, when someone is running the pipeline, they need to enter the ProductCode, then go look to a separate document to manually find the ProductId for that code and copy and paste it back into the pipeline field.

Is it possible to store that table somewhere so the user only needs to enter the ProductCode and a pipeline action can look up the Id? It needs to be easily accessible so DevOps users can add new products as required (e.g. not having to edit a powershell script or a text file stored in the code branch)

Share Improve this question asked Nov 18, 2024 at 21:23 komodospkomodosp 3,6584 gold badges37 silver badges68 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

You can use a variable group to store the list of ProductCode-ProductId pairs like as below:

  1. Create variable group (e.g., ProductCode_ProductId). In this group, the variable name is the value of ProductCode, and the variable value is the value of corresponding ProductId. When you have new ProductCode-ProductId pairs, you can add them into this group at anytime.

  2. In the YAML pipelines,

    • Reference the variable group created above.
    • Set up a parameter (ProductCode) to let users enter the value of ProductCode when manually triggering the pipeline.
    • Use the expression '${{ parameters.ProductCode }}' to get the value of ProductCode, and the expression '$(${{ parameters.ProductCode }})' to get the value of corresponding ProductId.
    parameters:
    - name: ProductCode
      type: string
      default: ''
    
    variables:
    - group: ProductCode_ProductId
    
    steps:
    - bash: |
        echo "ProductCode = ${{ parameters.ProductCode }}"
        echo "ProductId = $(${{ parameters.ProductCode }})"
      displayName: 'Print ProductCode and ProductId'
    

    You also can set up two variables and pass the expressions as their values like as below.

    parameters:
    - name: ProductCode
      type: string
      default: ''
    
    variables:
    - group: ProductCode_ProductId
    - name: ProductCode
      value: ${{ parameters.ProductCode }}
    - name: ProductId
      value: $(${{ parameters.ProductCode }})
    
    steps:
    - bash: |
        echo "ProductCode = $(ProductCode)"
        echo "ProductId = $(ProductId)"
      displayName: 'Print ProductCode and ProductId'
    
  3. Results.


发布评论

评论列表(0)

  1. 暂无评论