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 badges1 Answer
Reset to default 3You can use a variable group to store the list of ProductCode-ProductId
pairs like as below:
Create variable group (e.g.,
ProductCode_ProductId
). In this group, the variable name is the value ofProductCode
, and the variable value is the value of correspondingProductId
. When you have newProductCode-ProductId
pairs, you can add them into this group at anytime.In the YAML pipelines,
- Reference the variable group created above.
- Set up a parameter (
ProductCode
) to let users enter the value ofProductCode
when manually triggering the pipeline. - Use the expression '
${{ parameters.ProductCode }}
' to get the value ofProductCode
, and the expression '$(${{ parameters.ProductCode }})
' to get the value of correspondingProductId
.
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'
Results.