Reputation: 22
I'm aware that parameters cannot be optional. I'm building a pipeline with multiple stages, but I wanted to be able to run only certain stages at times.
Using parameters I can't just leave them blank and then use the logic IF PARAMETER IS EMPTY, SKIP STAGE. I could ask which resources to deploy in input, but then I can't ask again "hey based on the 3 you chose, I now need these 30 values".
Is there any way around this? Any other ideas on how to design something with the above requirements?
Something that occurred to me:
This isn't very user friendly but could work.
Thanks in advance
Upvotes: 0
Views: 1042
Reputation: 35099
Based on your requirement, you need to input the related parameters according to the selected stages.
I am afraid that there is no direct way can achieve your requirements.
Parameter assignment and stage manual selection are done at the same time, so it is not possible to set the required parameters based on the manually selected stage.
At the same time, the parameter value is not able to set as empty when running the pipeline. The value is required.
Is there any way around this? Any other ideas on how to design something with the above requirements?
I suggest that you can run the Pipeline stage based on the parameters value.
For the parameters value, you can set them to specific values(e.g. None) Then you can use expression to check if the stage needs to be run.
Here is YAML example:
parameters:
- name: test3
displayName: Run Tests?
default: 'None'
- name: test
displayName: Run Tests?
type: string
default: 'None'
- name: test1
displayName: Run Tests?
type: string
default: 'None'
- name: test2
displayName: Run Tests?
type: string
default: 'None'
stages:
- ${{ if and(ne(parameters.test3, 'None'), ne(parameters.test, 'None')) }}:
- stage: stage1
jobs:
- job: test1
steps:
- script: echo "1"
- ${{ if and(ne(parameters.test1, 'None'), ne(parameters.test2, 'None')) }}:
- stage: stage2
jobs:
- job: test2
steps:
- script: echo "1"
When the related parameters value is none, the stage will skip. Or if we input related values to all parameters, it will run the corresponding stage.
Upvotes: 0