Feb 02 2023
12:46 AM
- last edited on
Mar 05 2024
02:22 PM
by
TechCommunityAP
Feb 02 2023
12:46 AM
- last edited on
Mar 05 2024
02:22 PM
by
TechCommunityAP
Hello,
We have two Azure Plugin extensions (created using nodejs) to be used in our pipeline and they needs to be dependent. Review task is at CI stage, Publish task is at CD stage
sample code as in yaml
Plugin 1 - Review task
stage: CI
- task: ReviewAPI
displayName: do review for my API
inputs: <parameters>
stage: CD
Plugin 2 - publish task
- task: publishAPI
displayName: publish my API
inputs: <parameters>
publish task should be dependent on review task completion/success.
Question 1: how to make both tasks mandatory? Is there a way to enforce?
Question 2: Is it possible to add condition in PublishAPI to validate that ReviewAPI task is completed using condition variable?
Question 3: Is it possible that we can write artifactory/output variable in ReviewAPI task and validate that artifactory/output variable in publishAPI task?
Feb 02 2023 07:39 PM
Hi there@Guhanath
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:
Feb 05 2023 10:00 PM
Feb 06 2023 08:26 PM
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.