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)
You 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 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.
In the YAML pipelines,
ProductCode
) to let users enter the value of ProductCode
when manually triggering the pipeline.${{ 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'
Results.