One plugin task status as condition in another plugin task

Copper Contributor

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?

3 Replies

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:

Hi @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?

@Guhanath 

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.