Forum Discussion
One plugin task status as condition in another plugin task
Hi thereGuhanath
Answer 1: You can set the condition for each task to always run to make both tasks mandatory. For the ReviewAPI task, for example:
- task: ReviewAPI
displayName: do review for my API
inputs: <parameters>
condition: always()In addition, for the publishAPI task:
- task: publishAPI
displayName: publish my API
inputs: <parameters>
condition: always()Answer 2: A condition in the publishAPI task can be added to validate that the ReviewAPI task was completed. To check the status of the ReviewAPI task, use the succeeded() function:
- task: publishAPI
displayName: publish my API
inputs: <parameters>
condition: succeeded('ReviewAPI')Answer 3: Yes, an artifact/output variable can be created in the ReviewAPI task and validated in the publishAPI task. You can follow the steps. The name of the step is>. outputs syntax for accessing a previous task's output variables:
# ReviewAPI task
- task: ReviewAPI
displayName: do review for my API
inputs: <parameters>
outputs:
reviewResult: true
# publishAPI task
- task: publishAPI
displayName: publish my API
inputs: <parameters>
condition: eq(steps.ReviewAPI.outputs['reviewResult'], 'true')
Reference:
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml
- GuhanathFeb 06, 2023Copper ContributorHi 2MuchC0ff33,
Sorry for the delayed response. Thanks for your responses. will go through them.
Considering that these plugins are custom developed and developers will search and add them in their pipeline, is it possible to enforce them to use it?
Also, these plugins are written in node js, and is it possible to add these conditional parameters inside the code and be available when they drag and drop it in the pipeline?
eg: condition: succeeded('ReviewAPI')
or
outputs:
reviewResult: false
to be available when they are dragged and dropped in the pipeline and be changed when the task execution completed?- 2MuchC0ff33Feb 07, 2023Brass Contributor
You can include the conditions and outputs as part of the plugin code to enforce the use of the plugins and make the conditions and outputs available in the pipeline. When the plugin is added to the pipeline, the conditions and outputs are made available to the user and can be configured.
You can use the Azure DevOps task API to add the condition to the code for the PublishAPI task, for example:
const tl = require('@microsoft/azure-pipelines-task-lib/task'); tl.setTaskCondition('succeeded(\'ReviewAPI\')');You can also add it to the output variable as follows:
tl.setVariable('reviewResult', false); tl.setOutput('reviewResult', tl.getVariable('reviewResult'));When the plugin is added, these lines of code will make the condition and outputs available in the pipeline. The user can then customise them as needed.